//Cập nhật Brand public async Task <bool> Update(PlanDto model) { var plan = _mapper.Map <Plan>(model); _repoPlan.Update(plan); return(await _repoPlan.SaveAll()); }
public async ThreadTask.Task <bool> UpdateByIdAsync(PlanDto plan, int id) { var toUpdate = await db.Plans.Get(id); if (toUpdate == null) { return(false); } var modified = false; if (!string.IsNullOrEmpty(plan.Name)) { toUpdate.Name = plan.Name; modified = true; } if (plan.Description != null) { toUpdate.Description = plan.Description; modified = true; } if (plan.Modid != null) { toUpdate.Mod_Id = plan.Modid; modified = true; } toUpdate.Published = plan.Published; db.Plans.UpdateAsync(toUpdate); db.Save(); return(modified); }
public async Task <ActionResult> PlanCreate(PlanDto model, string materialHidden) { if (!materialHidden.IsEmpty()) { await _planService.CreatePlanMaterial(new PlanMaterial() { PlanId = model.PlanId, MaterialId = Guid.Parse(materialHidden), TechNumber = model.PlanMaterialDto.TechNumber, Price = model.PlanMaterialDto.Price, Num = model.PlanMaterialDto.Num, Note = model.PlanMaterialDto.Note, PlanDate = model.PlanMaterialDto.PlanDate, UpdateTime = DateTime.Now, CreateTime = DateTime.Now }); } var list = await _planService.GetMaterialByPlan(model.PlanId); return(View(new PlanDto() { PlanId = model.PlanId, ProjectName = model.ProjectName, PlanMaterialList = list })); }
public async Task <ActionResponse <PlanDto> > Update(PlanDto entityDto) { try { List <PlanDayDto> planDays = new List <PlanDayDto>(entityDto.PlanDays); entityDto.PlanDays = null; entityDto.PlanDaysId = null; var entityToUpdate = mapper.Map <PlanDto, Plan>(entityDto); unitOfWork.GetGenericRepository <Plan>().Update(entityToUpdate); unitOfWork.Save(); entityDto.PlanDays = planDays; if ((await ModifyPlanDays(entityDto)) .IsNotSuccess(out ActionResponse <PlanDto> modifyDaysResponse, out entityDto)) { return(modifyDaysResponse); } if ((await GetById(entityToUpdate.Id)).IsNotSuccess(out ActionResponse <PlanDto> getResponse, out entityDto)) { return(await ActionResponse <PlanDto> .ReturnError("Greška prilikom ažuriranja podataka za plan.")); } return(await ActionResponse <PlanDto> .ReturnSuccess(entityDto, "Plan uspješno ažuriran.")); } catch (Exception) { return(await ActionResponse <PlanDto> .ReturnError("Greška prilikom ažuriranja plana.")); } }
public async Task <IActionResult> PutPlan([FromRoute] int id, [FromBody] PlanDto plan) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != plan.Id) { return(BadRequest()); } try { await mediator.Send(new AddPlan(plan)); } catch (DbUpdateConcurrencyException) { if (await mediator.Send(new GetPlan(id)) == null) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <HttpResponseMessage> PostAndReturnIdAsync([FromBody] PlanDto value) { try { if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } int?result = await planService.AddAndGetIdAsync(value); if (result != null) { var log = $"Succesfully created plan {value.Name} with id = {result} by user with id = {value.CreatorId}"; tracer.Info(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, log); return(Request.CreateResponse(HttpStatusCode.OK, result)); } } catch (EntityException e) { tracer.Error(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, e); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e)); } tracer.Warn(Request, ControllerContext.ControllerDescriptor.ControllerType.FullName, "Error occured on creating plan"); const string message = "Incorrect request syntax."; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); }
public async Task <IActionResult> Update(PlanDto update) { if (await _planService.Update(update)) { return(NoContent()); } return(BadRequest($"Updating model no {update.ID} failed on save")); }
public async Task <IActionResult> Create(PlanDto create) { if (_planService.GetById(create.ID) != null) { return(BadRequest("Plan ID already exists!")); } create.CreatedDate = DateTime.Now; return(Ok(await _planService.Add(create))); }
//Cập nhật Brand public async Task <bool> Update(PlanDto model) { var plan = _mapper.Map <Plan>(model); plan.CreatedDate = DateTime.Now; _repoPlan.Update(plan); await _hubContext.Clients.All.SendAsync("summaryRecieve", "ok"); return(await _repoPlan.SaveAll()); }
public async Task PlanIsValidIfNoSections() { var plan = new PlanDto() { Name = "test" }; var result = await _planService.IsPlanFormatValid(plan); Assert.IsTrue(result); }
public async Task PlanIsInvalidIfItUsesLevelsFromWrongPatrol() { _planRepositoryMock.Setup(x => x.GetLevels(1)) .Returns(Task.FromResult(new List <Level>() { new Level() { Id = 1 } }.AsEnumerable())) .Verifiable(); _planRepositoryMock.Setup(x => x.GetSkills(1)) .Returns(Task.FromResult(new List <Skill>() { }.AsEnumerable())) .Verifiable(); var plan = new PlanDto() { Name = "test", PatrolId = 1, Sections = new List <SectionDto>() { new SectionDto() { Levels = new List <SectionLevelDto>() { new SectionLevelDto() { ColumnIndex = 0, Level = new Level() { Id = 1, } }, }, Skills = new List <SectionSkillDto>() { new SectionSkillDto() { RowIndex = 0, Skill = new Skill() { Id = 1 } }, } } } }; var result = await _planService.IsPlanFormatValid(plan); Assert.IsFalse(result); }
public async Task <IActionResult> Update(PlanDto update) { var model = await _planService.Update(update); if (model) { await _hubContext.Clients.All.SendAsync("ReceiveCreatePlan"); return(NoContent()); } return(BadRequest($"Updating model no {update.ID} failed on save")); }
public async Task UpdatePlanTest_ShouldReturnBadRequestMessage() { planServiceMock.Setup(u => u.UpdateByIdAsync(It.IsAny <PlanDto>(), It.IsAny <int>())).ReturnsAsync(false); PlanDto forUpdating = new PlanDto(1, "name1", "description1", true, 1, "nameCreator1", "lastenameCreator1", 1, "nameCreator1", "lastenameCreator1", DateTime.Now, DateTime.Now); var response = await planController.PutAsync(1, forUpdating); var expectedStatusCode = HttpStatusCode.BadRequest; var actualStatusCode = response.StatusCode; Assert.AreEqual(expectedStatusCode, actualStatusCode); }
public async Task <ActionResult> ConstructionEdit(PlanDto plan) { await GetOtherSysDepart(1, plan.SysDepartId); return(View(new PlanDto() { Id = plan.Id, ProjectId = plan.ProjectId, SysDepartOwnerName = plan.SysDepartName, ProjectName = plan.ProjectName })); }
//Thêm Brand mới vào bảng Plan public async Task <bool> Add(PlanDto model) { var plan = _mapper.Map <Plan>(model); plan.CreatedDate = DateTime.Now; plan.BPFCEstablishID = model.BPFCEstablishID; _repoPlan.Add(plan); var result = await _repoPlan.SaveAll(); await _hubContext.Clients.All.SendAsync("summaryRecieve", "ok"); return(result); }
public async Task UpdatePlanTest_ShouldCatchEntityExeption() { planServiceMock.Setup(u => u.UpdateByIdAsync(It.IsAny <PlanDto>(), It.IsAny <int>())) .Throws(new EntityException()); PlanDto forUpdating = new PlanDto(1, "name1", "description1", true, 1, "nameCreator1", "lastenameCreator1", 1, "nameCreator1", "lastenameCreator1", DateTime.Now, DateTime.Now); var response = await planController.PutAsync(1, forUpdating); var expectedStatusCode = HttpStatusCode.InternalServerError; var actualStatusCode = response.StatusCode; Assert.AreEqual(expectedStatusCode, actualStatusCode); }
public void CreateOrUpdateSignOnPlan(PlanDto f) { var client = new SignonPlans() { Id = f.Id, PlanName = f.PlanName, HeaderColor = f.HeaderColor.ToLower(), Members = f.Members, Price = f.Price, }; _signonplans.InsertOrUpdate(client); }
public async Task <IActionResult> PostPlan([FromBody] PlanDto plan) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await mediator.Send(new AddPlan(plan))) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> Create(PlanDto create) { if (_planService.GetById(create.ID) != null) { return(BadRequest("Plan ID already exists!")); } create.CreatedDate = DateTime.Now; if (await _planService.Add(create)) { return(NoContent()); } throw new Exception("Creating the model no failed on save"); }
public async Task <IActionResult> Create(PlanDto create) { if (_planService.GetById(create.ID) != null) { return(BadRequest("Plan ID already exists!")); } create.CreatedDate = DateTime.Now; var model = await _planService.Add(create); if (model) { await _hubContext.Clients.All.SendAsync("ReceiveCreatePlan"); } return(Ok(model)); }
public async Task <ActionResult <PlanDto> > CreatePlan(PlanDto plan) { try { if (plan == null) { return(BadRequest()); } return(await _planService.AddPlan(plan)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database")); } }
/// <summary> /// inside this method we call the rest api and retrieve a data /// </summary> /// <returns></returns> protected async override Task OnInitializedAsync() { int.TryParse(Id, out int planId); if (planId != 0) { Plan = await PlanService.GetPlan(int.Parse(Id)); AutumnSemester = Plan.AutumnSemester; SpringSemester = Plan.SpringSemester; Semesters = new List <SemesterDto> { AutumnSemester, SpringSemester }; SemesterId = Semester.SemesterId.ToString(); ModuleId = Module.ModuleId.ToString(); Lmr = new LecturerModuleRunDto(); SelectedPlanId = Plan.Id; ListLmr = (await LecturerModuleRunService.GetLecturerModuleRuns()).ToList(); foreach (var sem in Semesters) { foreach (var mr in sem.ModuleRuns) { ModuleRuns.Add(mr); } } await ShowLastYearPlan(); } else { Plan = new PlanDto { }; Semester = new SemesterDto { }; Module = new ModuleDto { }; ListLmr = new List <LecturerModuleRunDto> { }; } Plans = (await PlanService.GetPlans()).ToList(); ModuleRuns = (await ModuleRunService.GetModuleRuns()).ToList(); Modules = (await ModuleService.GetModules()).ToList(); Lecturers = (await LecturerService.GetLecturers()).ToList(); LecturerGroups = (await LecturerGroupService.GetLecturerGroups()).ToList(); }
public async Task PlanIsInValidIfItHasEmptySections() { var plan = new PlanDto() { Name = "test", Sections = new List <SectionDto>() { new SectionDto() { } } }; var result = await _planService.IsPlanFormatValid(plan); Assert.IsFalse(result); }
public void Handle(NewPlanDefinedEvent args) { var plansCollection = _mongoDataBase.GetCollection <PlanDto>("Plans"); var newPlan = new PlanDto { CompanyId = args.CompanyId, Description = args.Description, Id = args.PlanId, Name = args.Name, PlanType = args.PlanType, PlanYears = new List <string>(), }; plansCollection.Save(newPlan); }
public async ThreadTask.Task <int?> AddAndGetIdAsync(PlanDto dto) { if (!(await db.Users.ContainsIdAsync(dto.CreatorId))) { return(null); } var plan = new Plan { Name = dto.Name, Description = dto.Description, Create_Id = dto.CreatorId, Published = dto.Published }; var createdPlan = db.Plans.AddAndReturnElement(plan); db.Save(); return(createdPlan?.Id); }
public async ThreadTask.Task <bool> AddAsync(PlanDto dto) { if (!await ContainsId(dto.CreatorId)) { return(false); } var plan = new Plan { Name = dto.Name, Description = dto.Description, Create_Id = dto.CreatorId, Published = dto.Published }; db.Plans.AddAsync(plan); db.Save(); return(true); }
private async Task <ActionResponse <PlanDto> > ModifyPlanDays(PlanDto plan) { try { var entity = unitOfWork.GetGenericRepository <Plan>() .FindBy(p => p.Id == plan.Id, includeProperties: "PlanDays.Subjects.PlanDaySubjectThemes.Theme"); plan.PlanDaysId = null; var currentDays = mapper.Map <List <PlanDay>, List <PlanDayDto> >(entity.PlanDays.ToList()); var newDays = plan.PlanDays; var daysToRemove = currentDays.Where(cd => !newDays.Select(nd => nd.Id).Contains(cd.Id)).ToList(); var daysToAdd = newDays .Where(nt => !currentDays.Select(cd => cd.Id).Contains(nt.Id)) .Select(pd => { pd.PlanId = plan.Id; return(pd); }) .ToList(); var daysToModify = newDays.Where(cd => currentDays.Select(nd => nd.Id).Contains(cd.Id)).ToList(); if ((await RemoveDaysFromPlan(daysToRemove)) .IsNotSuccess(out ActionResponse <List <PlanDayDto> > actionResponse)) { return(await ActionResponse <PlanDto> .ReturnError("Neuspješno ažuriranje dana u planu.")); } if ((await AddDaysToPlan(daysToAdd)).IsNotSuccess(out actionResponse)) { return(await ActionResponse <PlanDto> .ReturnError("Neuspješno ažuriranje dana u planu.")); } if ((await ModifyDaysInPlan(daysToModify)).IsNotSuccess(out actionResponse)) { return(await ActionResponse <PlanDto> .ReturnError("Neuspješno ažuriranje dana u planu.")); } return(await ActionResponse <PlanDto> .ReturnSuccess(plan, "Uspješno izmijenjeni dani plana.")); } catch (Exception) { return(await ActionResponse <PlanDto> .ReturnError("Greška prilikom modifikacije dana za plan.")); } }
public void CreatesPlan_ShouldBeGetedPlan() { var planDto = new PlanDto() { Name = "", PaymentAmount = "20", PaymentCycles = "1", PaymentFrequency = "1", PaymentCurrency = "USD", PaymentFrequencyInterval = "monthly", OwnerId = 1, Description = "Description" }; var idPlan = _paymentService.CreatePlan(planDto); var createdPlan = _planRepository.GetById(idPlan); //Assert.Equals(planDto.Name, createdPlan.Name); }
public async Task <ActionResult <PlanDto?> > UpdatePlan(PlanDto plan) { try { var planForUpdate = await _planService.GetPlan(plan.Id); if (planForUpdate == null) { return(NotFound($"Plan with id = {plan.Id} not found")); } return(await _planService.UpdatePlan(plan)); } catch (Exception ex) { _logger.LogError(SR.ErrorRetrievingDataFromDataBase, ex); return(StatusCode(StatusCodes.Status500InternalServerError, SR.ErrorUpdatingDatabase)); } }
public IEnumerable <PlanPriceDto> Get(Guid id) { Plan plan = _planRepository.GetAllIncluding(x => x.PlanPrices).Single(x => x.Id == id); IEnumerable <PlanPrice> planPrices = _planPriceRepository.GetByPlan(plan.Id); PlanDto planDto = _mapper.Map <PlanDto>(plan); return(planPrices.Select(x => { return new PlanPriceDto { Id = x.Id, Plan = planDto, PlanId = planDto.Id, Currency = x.Currency.Code.ToString(), Price = x.Price }; })); }