Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.LINQDataAccess/3.2/UptimeCalendarDao.cs @ 3022

Last change on this file since 3022 was 3022, checked in by kgrading, 14 years ago

added the calendar in the dal and the server console. Works on every Resource (Group / Client) (#908)

File size: 3.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Hive.Contracts.BusinessObjects;
6using HeuristicLab.Hive.Server.DataAccess;
7
8namespace HeuristicLab.Hive.Server.LINQDataAccess {
9  public class UptimeCalendarDao: BaseDao<AppointmentDto, UptimeCalendar>, IUptimeCalendarDao {
10    public override UptimeCalendar DtoToEntity(AppointmentDto source, UptimeCalendar target) {
11      if(source == null)
12        return null;
13      if (target == null)
14        target = new UptimeCalendar();
15
16      target.AllDayEvent = source.AllDayEvent;
17      target.EndDate = source.EndDate;
18      target.StartDate = source.StartDate;
19      target.Recurring = source.Recurring;
20      target.RecurringId = source.RecurringId;
21
22      target.ResourceId = source.ResourceId;
23
24      return target;
25     
26    }
27
28    public override AppointmentDto EntityToDto(UptimeCalendar source, AppointmentDto target) {
29      if (source == null)
30        return null;
31      if (target == null)
32        target = new AppointmentDto();
33     
34      target.AllDayEvent = source.AllDayEvent;
35      target.EndDate = source.EndDate;
36      target.StartDate = source.StartDate;
37      target.Recurring = source.Recurring;
38      target.RecurringId = source.RecurringId;
39
40      target.ResourceId = source.ResourceId;
41
42      return target;
43
44    }
45
46    #region IGenericDao<AppointmentDto> Members
47
48    public AppointmentDto FindById(Guid id) {
49      return (from app in Context.UptimeCalendars
50              where app.UptimeCalendarId.Equals(id)
51              select EntityToDto(app, null)).SingleOrDefault();
52    }
53
54    public IEnumerable<AppointmentDto> FindAll() {
55      return (from app in Context.UptimeCalendars             
56              select EntityToDto(app, null)).ToList();
57    }
58
59    public AppointmentDto Insert(AppointmentDto bObj) {
60      UptimeCalendar uc = DtoToEntity(bObj, null);
61      Context.UptimeCalendars.InsertOnSubmit(uc);
62      Context.SubmitChanges();
63      bObj.Id = uc.UptimeCalendarId;
64      return bObj;
65    }
66
67    public void Delete(AppointmentDto bObj) {
68      Context.UptimeCalendars.DeleteOnSubmit(Context.UptimeCalendars.SingleOrDefault(uc => uc.UptimeCalendarId.Equals(bObj.Id)));
69      Context.SubmitChanges();
70    }
71
72    public void Update(AppointmentDto bObj) {
73      UptimeCalendar cc = Context.UptimeCalendars.SingleOrDefault(c => c.UptimeCalendarId.Equals(bObj.Id));
74      DtoToEntity(bObj, cc);
75      Context.SubmitChanges();
76    }
77
78    public IEnumerable<AppointmentDto> GetUptimeCalendarForResource(Guid resourceId) {
79      return (from uc in Context.UptimeCalendars
80              where uc.ResourceId.Equals(resourceId)
81              select EntityToDto(uc, null)).ToList();
82    }
83
84    public void SetUptimeCalendarForResource(Guid resourceId, IEnumerable<AppointmentDto> appointments) {
85      var q = (from uc in Context.UptimeCalendars
86               where uc.ResourceId.Equals(resourceId)
87               select uc);
88     
89      Context.UptimeCalendars.DeleteAllOnSubmit(q);
90
91      foreach (AppointmentDto appdto in appointments) {     
92        UptimeCalendar uc = DtoToEntity(appdto, null);
93        uc.ResourceId = resourceId;
94        Context.UptimeCalendars.InsertOnSubmit(uc);
95      }
96
97      Context.SubmitChanges();           
98    }
99
100    #endregion
101  }
102}
Note: See TracBrowser for help on using the repository browser.