public async Task <IActionResult> Edit(int id, [Bind("Id,CompanyId,ReportCode,ApplicationMethodId,IsPresentationDone,PresentationDate,PresentationFile,MarketingMethodId,ProposedBudget,ProposalDate,CompanyRequests,ConsultancyStartDate,ConsultancyFinishDate,ReportCreateDate,ReportCreatedById,ReportSendDate,ConsultantNotes,CreateDate,CreatedBy,UpdateDate,UpdatedBy,ServiceFields")] Consultancy consultancy, IFormFile presentationUpload) { if (id != consultancy.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (presentationUpload != null && presentationUpload.Length > 0) { string presentationName = new Random().Next(9999).ToString() + presentationUpload.FileName; using (var stream = new FileStream(env.WebRootPath + "\\uploads\\presentationFiles\\" + presentationName, FileMode.Create)) { presentationUpload.CopyTo(stream); } consultancy.PresentationFile = presentationName; } _context.ConsultancyServiceFields.RemoveRange(_context.ConsultancyServiceFields.Where(w => w.ConsultancyId == id).ToList()); _context.SaveChanges(); _context.Update(consultancy); _context.SaveChanges(); if (consultancy.ServiceFields != null) { foreach (var serviceField in consultancy.ServiceFields) { consultancy.ConsultancyServiceFields.Add(new ConsultancyServiceField() { ConsultancyId = consultancy.Id, ServiceFieldId = serviceField }); } } consultancy.UpdatedBy = User.Identity.Name; consultancy.UpdateDate = DateTime.Now; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConsultancyExists(consultancy.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["ApplicationMethodId"] = new SelectList(_context.ApplicationMethods, "Id", "Name", consultancy.ApplicationMethodId); ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", consultancy.CompanyId); ViewData["MarketingMethodId"] = new SelectList(_context.MarketingMethods, "Id", "Name", consultancy.MarketingMethodId); ViewData["ReportCreatedById"] = new SelectList(_context.ApplicationUser, "Id", "FullName", consultancy.ReportCreatedById); ViewData["ServiceFields"] = new MultiSelectList(_context.ServiceFields, "Id", "Name", consultancy.ServiceFields); return(View(consultancy)); }
public void WhenTheConsultantScheduleAConsultancySession(Table table) { consultancy = table.CreateInstance <Consultancy>(); consultancy = new Consultancy() { Diagnosis = "Se va a quiebra", Recommendation = "Mejorar administracion de finanzas" }; restRequest.AddJsonBody(consultancy); response = restClient.Execute(restRequest); }
public async Task <ConsultancyResponse> SaveAsync(Consultancy consultancy) { try { await _consultancyRepository.AddAsync(consultancy); await _unitOfWork.CompleteAsync(); return(new ConsultancyResponse(consultancy)); } catch (Exception ex) { return(new ConsultancyResponse($"An error ocurred when while saving consultancy: {ex.Message}")); } }
public int SaveConsulatancy(string content, string name, int id) { var consultancy = new Consultancy { created_at = DateTime.Now, modified_at = DateTime.Now, data = content, proj_id = id, name = name }; _insendluEntities.Consultancies.Add(consultancy); return(_insendluEntities.SaveChanges()); }
// GET: Consultancies/Create public IActionResult Create() { ViewData["ApplicationMethodId"] = new SelectList(_context.ApplicationMethods, "Id", "Name"); ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name"); ViewData["MarketingMethodId"] = new SelectList(_context.MarketingMethods, "Id", "Name"); ViewData["ReportCreatedById"] = new SelectList(_context.ApplicationUser, "Id", "FullName"); ViewData["ServiceFields"] = new MultiSelectList(_context.ServiceFields, "Id", "Name"); var model = new Consultancy(); model.CreatedBy = User.Identity.Name; model.UpdatedBy = User.Identity.Name; model.UpdateDate = DateTime.Now; model.CreateDate = DateTime.Now; return(View(model)); }
public async Task <IActionResult> Create([Bind("Id,CompanyId,ReportCode,ApplicationMethodId,IsPresentationDone,PresentationDate,PresentationFile,MarketingMethodId,ProposedBudget,ProposalDate,CompanyRequests,ConsultancyStartDate,ConsultancyFinishDate,ReportCreateDate,ReportCreatedById,ReportSendDate,ConsultantNotes,CreateDate,CreatedBy,UpdateDate,UpdatedBy,ServiceFields")] Consultancy consultancy, IFormFile presentationUpload) { if (ModelState.IsValid) { if (presentationUpload != null && presentationUpload.Length > 0) { string presentationName = new Random().Next(9999).ToString() + presentationUpload.FileName; using (var stream = new FileStream(env.WebRootPath + "\\uploads\\presentationFiles\\" + presentationName, FileMode.Create)) { presentationUpload.CopyTo(stream); } consultancy.PresentationFile = presentationName; } _context.Add(consultancy); await _context.SaveChangesAsync(); consultancy.ConsultancyServiceFields.Clear(); if (consultancy.ServiceFields != null) { foreach (var serviceField in consultancy.ServiceFields) { consultancy.ConsultancyServiceFields.Add(new ConsultancyServiceField() { ConsultancyId = consultancy.Id, ServiceFieldId = serviceField }); } } await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["ApplicationMethodId"] = new SelectList(_context.ApplicationMethods, "Id", "Name", consultancy.ApplicationMethodId); ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", consultancy.CompanyId); ViewData["MarketingMethodId"] = new SelectList(_context.MarketingMethods, "Id", "Name", consultancy.MarketingMethodId); ViewData["ReportCreatedById"] = new SelectList(_context.ApplicationUser, "Id", "FullName", consultancy.ReportCreatedById); ViewData["ServiceFields"] = new MultiSelectList(_context.ServiceFields, "Id", "Name", consultancy.ServiceFields); return(View(consultancy)); }
public async Task <ConsultancyResponse> UpdateAsync(int id, Consultancy consultancy) { var existingConsultancy = await _consultancyRepository.FindById(id); if (existingConsultancy == null) { return(new ConsultancyResponse("Consultancy no found")); } existingConsultancy.Diagnosis = consultancy.Diagnosis; existingConsultancy.Recommendation = consultancy.Recommendation; try { _consultancyRepository.Update(existingConsultancy); await _unitOfWork.CompleteAsync(); return(new ConsultancyResponse(existingConsultancy)); } catch (Exception ex) { return(new ConsultancyResponse($"An error ocurred when while saving consultancy: {ex.Message}")); } }
public async Task <ConsultancyChatDTO> GetOrCreateNewChatMessagesAsync(int serviceSupplyId, string userMobile, Lang lang, int?currentChatId = null) { var person = await _dbContext.Persons.FirstOrDefaultAsync(x => x.Mobile == userMobile); if (person == null) { throw new AwroNoreException("Not any person found for this mobile number"); } var appSettings = _options.Value.AwroNoreSettings; var chatscreenMention = lang == Lang.KU ? appSettings.ChatScreenMention.MentionKu : lang == Lang.AR ? appSettings.ChatScreenMention.MentionAr : appSettings.ChatScreenMention.Mention; var consultantStatus = lang == Lang.KU ? appSettings.ConsultantDefaultStatus.StatusKu : lang == Lang.AR ? appSettings.ConsultantDefaultStatus.StatusAr : appSettings.ConsultantDefaultStatus.Status; if (currentChatId != null) { var currentChat = await _dbContext.Consultancies.FindAsync(currentChatId.Value); if (currentChat == null) { throw new AwroNoreException("This chat is no longer available"); } if (currentChat.ServiceSupplyId != serviceSupplyId) { throw new AwroNoreException("Current chat contact is wrong"); } var form = await _dbContext.DiseaseRecordsForms.FirstOrDefaultAsync(x => x.PersonId == currentChat.PersonId); var result = new ConsultancyChatDTO { Id = currentChat.Id, Status = currentChat.Status != ConsultancyStatus.REMOVED_BY_DOCTOR ? currentChat.Status : ConsultancyStatus.FINISHED, ChatScreenMention = chatscreenMention, ContactStatus = consultantStatus, Messages = currentChat.ConsultancyMessages.Select(x => new ConsultancyMessageDTO { Id = x.Id, SenderReceiverType = x.Sender == ConsultancyMessageSender.CUSTOMER ? MessageSenderReceiverType.SENT : MessageSenderReceiverType.RECEIVED, ContactName = x.Sender == ConsultancyMessageSender.CUSTOMER ? (lang == Lang.KU ? x.Person.FullName_Ku : lang == Lang.AR ? x.Person.FullName_Ar : x.Person.FullName) : (lang == Lang.KU ? x.ServiceSupply.Person.FullName_Ku : lang == Lang.AR ? x.ServiceSupply.Person.FullName_Ar : x.ServiceSupply.Person.FullName), ContactAvatar = x.Sender == ConsultancyMessageSender.CUSTOMER ? x.Person.RealAvatar : x.ServiceSupply.Person.RealAvatar, Message = x.Content, Time = x.CreatedAt.ToString("HH:mm"), Type = x.Type, }).ToList(), DiseaseRecordsForm = form == null ? null : new AN.Core.DTO.Profile.DiseaseRecordsFormDTO { Age = form.Age, DoYouSmoke = form.DoYouSmoke, DrugsYouUsed = form.DrugsYouUsed, HadSurgery = form.HadSurgery, HasLongTermDisease = form.HasLongTermDisease, LongTermDiseasesDescription = form.LongTermDiseasesDescription, MedicalAllergies = form.MedicalAllergies, PersonId = person.Id, SurgeriesDescription = form.SurgeriesDescription } }; return(result); } // Create new consultancy else { var notFinishedChat = await _dbContext.Consultancies.FirstOrDefaultAsync(x => x.ServiceSupplyId == serviceSupplyId && x.PersonId == person.Id && x.Status != ConsultancyStatus.FINISHED && x.Status != ConsultancyStatus.REMOVED_BY_DOCTOR); if (notFinishedChat != null) { var form = await _dbContext.DiseaseRecordsForms.FirstOrDefaultAsync(x => x.PersonId == notFinishedChat.PersonId); var result = new ConsultancyChatDTO { Id = notFinishedChat.Id, Status = notFinishedChat.Status != ConsultancyStatus.REMOVED_BY_DOCTOR ? notFinishedChat.Status : ConsultancyStatus.FINISHED, ChatScreenMention = chatscreenMention, ContactStatus = consultantStatus, Messages = notFinishedChat.ConsultancyMessages.Select(x => new ConsultancyMessageDTO { Id = x.Id, SenderReceiverType = x.Sender == ConsultancyMessageSender.CUSTOMER ? MessageSenderReceiverType.SENT : MessageSenderReceiverType.RECEIVED, ContactName = x.Sender == ConsultancyMessageSender.CUSTOMER ? x.Person.FullName : x.ServiceSupply.Person.FullName, ContactAvatar = x.Sender == ConsultancyMessageSender.CUSTOMER ? x.Person.RealAvatar : x.ServiceSupply.Person.RealAvatar, Message = x.Content, Time = x.CreatedAt.ToString("HH:mm"), Type = x.Type, }).ToList(), DiseaseRecordsForm = form == null ? null : new AN.Core.DTO.Profile.DiseaseRecordsFormDTO { Age = form.Age, DoYouSmoke = form.DoYouSmoke, DrugsYouUsed = form.DrugsYouUsed, HadSurgery = form.HadSurgery, HasLongTermDisease = form.HasLongTermDisease, LongTermDiseasesDescription = form.LongTermDiseasesDescription, MedicalAllergies = form.MedicalAllergies, PersonId = person.Id, SurgeriesDescription = form.SurgeriesDescription } }; return(result); } else { var consultancy = new Consultancy { PersonId = person.Id, ServiceSupplyId = serviceSupplyId, CreatedAt = DateTime.Now, Status = ConsultancyStatus.NEW }; await _dbContext.Consultancies.AddAsync(consultancy); await _dbContext.SaveChangesAsync(); var form = await _dbContext.DiseaseRecordsForms.FirstOrDefaultAsync(x => x.PersonId == consultancy.PersonId); var result = new ConsultancyChatDTO { Id = consultancy.Id, ChatScreenMention = chatscreenMention, ContactStatus = consultantStatus, Messages = new List <ConsultancyMessageDTO>(), DiseaseRecordsForm = form == null ? null : new AN.Core.DTO.Profile.DiseaseRecordsFormDTO { Age = form.Age, DoYouSmoke = form.DoYouSmoke, DrugsYouUsed = form.DrugsYouUsed, HadSurgery = form.HadSurgery, HasLongTermDisease = form.HasLongTermDisease, LongTermDiseasesDescription = form.LongTermDiseasesDescription, MedicalAllergies = form.MedicalAllergies, PersonId = person.Id, SurgeriesDescription = form.SurgeriesDescription } }; return(result); } } }
public void Remove(Consultancy consultancy) { _context.Consultancies.Remove(consultancy); }
public void Update(Consultancy consultancy) { _context.Consultancies.Update(consultancy); }
public async Task AddAsync(Consultancy consultancy) { await _context.Consultancies.AddAsync(consultancy); }