// POST api/customers public HttpResponseMessage Post([FromBody] Rld.Acs.Model.TimeZone timeZoneInfo) { return(ActionWarpper.Process(timeZoneInfo, OperationCodes.ATMZN, () => { var timeZoneRepo = RepositoryManager.GetRepository <ITimeZoneRepository>(); var timeZoneGroupRepo = RepositoryManager.GetRepository <ITimeZoneGroupRepository>(); var timeGroupRepo = RepositoryManager.GetRepository <ITimeGroupRepository>(); if (timeZoneInfo == null) { return Request.CreateResponse(HttpStatusCode.BadRequest, "timeZoneInfo is null"); } if (timeZoneRepo.Query(new Hashtable() { { "TimeZoneCode", timeZoneInfo.TimeZoneCode } }).Any()) { return new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(string.Format("系统中已经存在编号为{0}的时间区", timeZoneInfo.TimeZoneCode)), ReasonPhrase = ConstStrings.BusinessLogicError, }; } timeZoneRepo.Insert(timeZoneInfo); timeZoneInfo.TimeGroupAssociations.ForEach(t => t.TimeZoneID = timeZoneInfo.TimeZoneID); timeZoneInfo.TimeGroupAssociations.ForEach(t => timeZoneGroupRepo.Insert(t)); return Request.CreateResponse(HttpStatusCode.OK, timeZoneInfo); }, this)); }
// PUT api/customers/5 public HttpResponseMessage Put(int id, [FromBody] Rld.Acs.Model.TimeZone timeZoneInfo) { return(ActionWarpper.Process(timeZoneInfo, OperationCodes.MTMZN, () => { if (timeZoneInfo == null) { return Request.CreateResponse(HttpStatusCode.BadRequest, "timeZoneInfo is null"); } timeZoneInfo.TimeZoneID = id; var timeZoneRepo = RepositoryManager.GetRepository <ITimeZoneRepository>(); var timeZoneGroupRepo = RepositoryManager.GetRepository <ITimeZoneGroupRepository>(); var timeGroupRepo = RepositoryManager.GetRepository <ITimeGroupRepository>(); var originalTimeZoneInfo = timeZoneRepo.GetByKey(id); if (originalTimeZoneInfo == null) { return Request.CreateResponse(HttpStatusCode.BadRequest, string.Format("TimeZone Id={0} does not exist.", id)); } if (timeZoneRepo.Query(new Hashtable() { { "TimeZoneCode", timeZoneInfo.TimeZoneCode } }).Any(x => x.TimeZoneID != id)) { return new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(string.Format("系统中已经存在编号为{0}的时间区", timeZoneInfo.TimeZoneCode)), ReasonPhrase = ConstStrings.BusinessLogicError, }; } var addedTimeGroups = new List <TimeZoneGroup>(); var deletedTimeGroupIds = new List <int>(); if (timeZoneInfo.TimeGroupAssociations != null && timeZoneInfo.TimeGroupAssociations.Any()) { var originalTimeGroupAssociationIDs = originalTimeZoneInfo.TimeGroupAssociations.Select(d => d.TimeZoneGroupID); var timeGroupAssociationIDs = timeZoneInfo.TimeGroupAssociations.Select(d => d.TimeZoneGroupID); deletedTimeGroupIds = originalTimeGroupAssociationIDs.Except(timeGroupAssociationIDs).ToList(); addedTimeGroups = timeZoneInfo.TimeGroupAssociations.FindAll(d => d.TimeZoneGroupID == 0); } else { deletedTimeGroupIds = originalTimeZoneInfo.TimeGroupAssociations.Select(d => d.TimeZoneGroupID).ToList(); } deletedTimeGroupIds.ForEach(d => timeZoneGroupRepo.Delete(d)); addedTimeGroups.ForEach(d => timeZoneGroupRepo.Insert(d)); timeZoneInfo.TimeGroupAssociations.FindAll(d => d.TimeZoneGroupID != 0).ForEach(d => timeZoneGroupRepo.Update(d)); timeZoneRepo.Update(timeZoneInfo); return Request.CreateResponse(HttpStatusCode.OK); }, this)); }
public TimeZoneViewModel(RldModel.TimeZone timeZone) { ViewModelAttachment = new ViewModelAttachment <RldModel.TimeZone>(); SaveCmd = new RelayCommand(Save); CancelCmd = new RelayCommand(() => Close("")); CurrentTimeZone = timeZone; if (timeZone.TimeZoneID != 0) { ID = timeZone.TimeZoneID; Name = timeZone.TimeZoneName; Code = timeZone.TimeZoneCode; } Title = (timeZone.TimeZoneID == 0) ? "新增时间区" : "修改时间区"; TimeGroupAssociationsDtos = InitTimeZoneGroupDtos(); }
private TimeZoneGroupMappingInfo BuildMappingInfo(RldModel.TimeZone timeZone, int index) { int id = 0; string name = ""; TimeGroup timeGroup = new TimeGroup(); var association = timeZone.TimeGroupAssociations.FirstOrDefault(t => t.DisplayOrder == index); if (association != null) { id = association.TimeZoneGroupID; timeGroup = AllTimeGroups.FirstOrDefault(t => t.TimeGroupID == association.TimeGroupID); } else { timeGroup = AllTimeGroups.First(); } switch (index) { case 1: name = "星期一"; break; case 2: name = "星期二"; break; case 3: name = "星期三"; break; case 4: name = "星期四"; break; case 5: name = "星期五"; break; case 6: name = "星期六"; break; case 7: name = "星期日"; break; } return(new TimeZoneGroupMappingInfo() { ID = id, DisplayOrder = index, Name = name, SelectedTimeGroupName = timeGroup.TimeGroupName, TimeGroupViewModel = new TimeGroupViewModel(timeGroup), }); }