public bool Add(CatalogViewModel entityvm) { try { var entity = Mapper.Map <CatalogViewModel, Catalog>(entityvm); _catalogRepository.Insert(entity); _unitOfWork.Commit(); return(true); } catch { return(false); } }
public async Task <RuleDTO> UpdateRuleStyle(RuleDTO newRuleDto, IEnumerable <FileDataDTO> fileDtos, string userId, string entityId) { try { _muw.BeginTransaction(); if (fileDtos != null) { foreach (var fileData in fileDtos) { var EFFile = new EFFile { Data = fileData.Data, ContentType = fileData.ContentType, Length = fileData.Length, Name = fileData.Name }; _muw.Repository <EFFile>().Insert(EFFile); _muw.SaveChanges(); newRuleDto.Style.SetFilePropertyWithId(fileData.CssProperty, EFFile.Id); } } //remove old files var oldRuleDTO = await this.GetRuleDetails(newRuleDto.Id, userId, entityId); var clientFilePropertiesValues = newRuleDto.Style.GetFilePropertiesValues(); var oldFilePropertiesValues = oldRuleDTO.Style.GetFilePropertiesValues(); foreach (var oldFileIdValue in oldFilePropertiesValues) { if (!clientFilePropertiesValues.Contains(oldFileIdValue))//the file is delete or replaced with another one, then delete old one { _muw.Repository <EFFile>().Delete(_muw.Repository <EFFile>().FirstOrDefault(fd => fd.Id == oldFileIdValue)); } } _muw.SaveChanges(); var oldEFRule = _muw.Repository <EFRule>().GetList(r => r.Id == newRuleDto.Id).FirstOrDefault(); if (oldRuleDTO == null) { throw new Exception("No Css rule with Id=" + newRuleDto.Id); } oldEFRule.SetRuleStyle(newRuleDto.Style, userId, entityId); _muw.SaveChanges(); _muw.Commit(); return(oldEFRule.GetRuleDTO(userId, entityId)); } catch (Exception ex) { _muw.Rollback(); throw ex; } }
public void Commit() { UnitOfWork.Commit(); }
public void Save() { _unitOfWork.Commit(); }