public void Save(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); service.IdAccount = idAccount; //Cuando es un nuevo servicio if (service.Id == Guid.Empty) { _serviceDao.InsertOrUpdate(service); } //Cuando es un servicio existente else { var exService = _serviceDao.GetOne(service.Id, idAccount); PropertyCopy.Copy(service, exService); service = null; //_serviceDao.Context.SaveChanges(); //_serviceDao.InsertOrUpdate(exService); UpdateEntireService(exService, idAccount); } //UpdateEntireService(service, idAccount); }
public void Save(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); service.IdAccount = idAccount; //Cuando es un nuevo servicio if (service.Id == Guid.Empty) { _serviceDao.InsertOrUpdate(service); _redisCache.flush(service.Id.ToString()); } //Cuando es un servicio existente else { var exService = _serviceDao.GetOne(service.Id, idAccount); PropertyCopy.Copy(service, exService); service = null; //_serviceDao.Context.SaveChanges(); //_serviceDao.InsertOrUpdate(exService); UpdateEntireService(exService, idAccount); foreach (var item in _serviceDao.Getcampaign(exService.Id)) { _redisCache.flush("CampaignServices:" + item.IdCampaign.ToString()); } } //UpdateEntireService(service, idAccount); }
public static Service FromServiceRegisterViewModel(ServiceRegisterViewModel model) { return(new Service() { Id = (!string.IsNullOrEmpty(model.Id)) ? Guid.Parse(model.Id) : Guid.Empty, Name = model.Name, Code = model.Code, CreationDate = model.DateCreation, IdCustomer = Guid.Parse(model.IdCustomer), IdChannel = Guid.Parse(model.IdChannel), IdTypeService = Guid.Parse(model.IdTypeService), PollTitle = model.PollTitle, StatusRegister = model.StatusRegister, Icon = model.Icon, IconColor = model.IconColor, Template = model.Template, ServiceDetails = model.ServiceDetailList.Select(s => new ServiceDetail() { Id = (!string.IsNullOrEmpty(s.Id))? Guid.Parse(s.Id):Guid.Empty, Order = s.Order, StatusRegister = s.StatusRegister, SectionTitle = s.SectionTitle, Weight = s.Weight, IsDynamic = s.IsDynamic, IdService = (!string.IsNullOrEmpty(s.IdService)) ? Guid.Parse(s.IdService):Guid.Empty, HasPhoto = s.HasPhoto, GroupName = s.GroupName, IdSection = s.IdSection, Sections = GetSectionChildrens(s), Questions = s.Questions.Select(q => new Question() { Id = (!string.IsNullOrEmpty(q.Id)) ? Guid.Parse(q.Id):Guid.Empty, IdServiceDetail = (!string.IsNullOrEmpty(q.IdServiceDetail)) ? Guid.Parse(q.IdServiceDetail):Guid.Empty, Title = q.Title, StatusRegister = q.StatusRegister, Order = q.Order, Weight = q.Weight, IdTypePoll = Guid.Parse(q.IdTypePoll), HasPhoto = q.HasPhoto ? "S" : "N", CountPhoto = 0, AnswerRequired = q.AnswerRequired, Aggregatefield = q.Aggregatefield, QuestionDetails = q.QuestionDetails.Select(qd => new QuestionDetail() { Id = (!string.IsNullOrEmpty(qd.Id)) ? Guid.Parse(qd.Id):Guid.Empty, IdQuestion = (!string.IsNullOrEmpty(qd.IdQuestion)) ? Guid.Parse(qd.IdQuestion):Guid.Empty, Order = qd.Order, Weight = qd.Weight, Answer = qd.Answer, IdQuestionLink = (!string.IsNullOrEmpty(qd.IdQuestionLink)) ? (Guid?)Guid.Parse(qd.IdQuestionLink) : null, IsNext = "N", StatusRegister = qd.StatusRegister , Aggregatefield = qd.Aggregatefield , Idconcept = qd.Idconcept }).ToList() }).ToList() }).ToList() }); }
public void AddQuestion(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); service = GenerateQuestion(service, CService.LastQuestion, Guid.Parse(model.CurrentSection), Guid.Empty); UpdateEntireService(service, idAccount); }
public void DeleteSection(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); var section = service.ServiceDetails.FirstOrDefault(s => s.Id == Guid.Parse(model.CurrentSection)); section.StatusRegister = CStatusRegister.Delete; _serviceDetailDao.InsertOrUpdate(section); }
public void AddSectionAfter(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); service = GenerateSection(service, CService.AfterSection, Guid.Parse(model.CurrentSection)); UpdateEntireService(service, idAccount); }
public ServiceRegisterViewModel AddSubSection(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); service = GenerateSubSection(service, Guid.Parse(model.CurrentSection)); return(GetServiceRegisterModel(idAccount, service.Id)); }
public void AddAnswerAfter(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); service = GenerateAnswer(service, CService.AfterAnswer, Guid.Parse(model.CurrentSection), Guid.Parse(model.CurrentQuestion), Guid.Parse(model.CurrentAnswer)); UpdateEntireService(service, idAccount); }
public void DeleteAnswer(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); var section = service.ServiceDetails.FirstOrDefault(s => s.Id == Guid.Parse(model.CurrentSection)); var question = section.Questions.FirstOrDefault(q => q.Id == Guid.Parse(model.CurrentQuestion)); var answer = question.QuestionDetails.FirstOrDefault(q => q.Id == Guid.Parse(model.CurrentAnswer)); answer.StatusRegister = CStatusRegister.Delete; _questionDetailDao.InsertOrUpdate(answer); }
public ServiceRegisterViewModel AddSection(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); service = GenerateSection(service, CService.LastSection, Guid.Empty); service = UpdateEntireService(service, idAccount); return(GetServiceRegisterModel(idAccount, service.Id)); }
public IActionResult DuplicateSection(ServiceRegisterViewModel model) { if (!ModelState.IsValid) { LoadViewData(model.IdCustomer, model.Id.ToString()); return(View("Register", model)); } _serviceBusiness.DuplicateSection(model, ApplicationUserCurrent.AccountId); return(RedirectToAction("Register", new { service = _protector.Protect(model.Id.ToString()) })); }
public ServiceRegisterViewModel GetService(string idService, IDataProtector protector, Guid accountId) { var model = new ServiceRegisterViewModel(); if (!string.IsNullOrEmpty(idService)) { var serviceId = Guid.Parse(protector.Unprotect(idService)); model = GetServiceRegisterModel(accountId, serviceId); } return(model); }
public void DuplicateSection(ServiceRegisterViewModel model, Guid idAccount) { var service = ConvertService.FromServiceRegisterViewModel(model); var section = GetCurrentSection(service, Guid.Parse(model.CurrentSection)); if (section.IdSection == Guid.Empty || section.IdSection == null) { var beforeSections = service.ServiceDetails.Where(s => s.Order <= section.Order).OrderBy(s => s.Order).ToList(); var afterSections = service.ServiceDetails.Where(s => s.Order > section.Order).OrderBy(s => s.Order).ToList(); service.ServiceDetails.Clear(); service.ServiceDetails.AddRange(beforeSections); section.Id = Guid.Empty; section.Questions.ForEach(q => q.Id = Guid.Empty); section.Questions.ForEach(q => q.QuestionDetails.ForEach(d => d.Id = Guid.Empty)); section.Sections.ForEach(a => a.Id = Guid.Empty); section.Sections.ForEach(a => a.Questions.ForEach(q => q.Id = Guid.Empty)); section.Sections.ForEach(a => a.Questions.ForEach(q => q.QuestionDetails.ForEach(d => d.Id = Guid.Empty))); service.ServiceDetails.Add(section); service.ServiceDetails.AddRange(afterSections); } else { var serviceDetail = service.ServiceDetails.FirstOrDefault(s => s.Id == section.IdSection); var beforeSections = serviceDetail.Sections.Where(s => s.Order <= section.Order).OrderBy(s => s.Order).ToList(); var afterSections = serviceDetail.Sections.Where(s => s.Order > section.Order).OrderBy(s => s.Order).ToList(); serviceDetail.Sections.Clear(); serviceDetail.Sections.AddRange(beforeSections); section.Id = Guid.Empty; section.Questions.ForEach(q => { q.Id = Guid.Empty; q.IdServiceDetail = Guid.Empty; }); section.Questions.ForEach(q => q.QuestionDetails.ForEach(d => { d.Id = Guid.Empty; d.IdQuestion = Guid.Empty; })); section = _serviceDetailDao.InsertOrUpdate(section); var newSection = _serviceDetailDao.GetNotTracked(section.Id, idAccount); if (newSection == null) { } newSection.Questions.ForEach(q => { q.ServiceDetail = null; q.QuestionDetails.ForEach(d => { d.Question = null; }); }); serviceDetail.Sections.Add(newSection); serviceDetail.Sections.AddRange(afterSections); var beforeDetails = service.ServiceDetails.Where(s => s.Order < serviceDetail.Order).OrderBy(s => s.Order).ToList(); var afterDetails = service.ServiceDetails.Where(s => s.Order > serviceDetail.Order).OrderBy(s => s.Order).ToList(); service.ServiceDetails.Clear(); service.ServiceDetails.AddRange(beforeDetails); service.ServiceDetails.Add(serviceDetail); service.ServiceDetails.AddRange(afterDetails); } //UpdateEntireService(service, idAccount); }