public IActionResult Post([FromBody] DealerDto dealerDto) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var dealer = Mapper.Map <Dealer>(dealerDto); if (_dealerRepository.DealerExists(dealer)) { return(StatusCode(500, "Dealer already exists.")); } var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var profile = _accountRepository.GetUserProfile(userId); var createdDealer = _dealerRepository.CreateDealer(dealer, profile.UserProfileId); if (createdDealer == null) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdDealerToReturn = Mapper.Map <DealerDto>(createdDealer); return(Created(createdDealerToReturn)); } catch (Exception ex) { _logger.LogError($"Failed in Post /Dealers: {ex}"); return(StatusCode(500, "A problem happened while handling your request.")); } }
public List <DealerActivityDto> GetDealerActivities(DealerDto dealer) { var activities = _dealerActivityRepository.GetAllList(p => p.DealerId == dealer.Id).OrderBy(p => p.Activity.Description) .ToList(); return(new List <DealerActivityDto>(activities.MapTo <List <DealerActivityDto> >())); }
// Allocate plots by Dealer public List <AllocatedPlotView> GetAllocatedPlotsByDealer(DealerDto dealer) { //get current active financial year; var current = _financialYearRepository.FirstOrDefault(c => c.IsActive == true); var plots = (from sheet in _tallySheetRepository.GetAll() join plot in _plotRepository.GetAll() on sheet.PlotId equals plot.Id join allocated in _allocatedPlotRepository.GetAll() on plot.Id equals allocated.PlotId where allocated.DealerId == dealer.Id where allocated.FinancialYearId == current.Id where plot.IsAllocated == true where allocated.IsPaid == false orderby plot.Name group sheet by sheet.PlotId into g select new AllocatedPlotView { Id = g.Key, DealerId = dealer.Id, Name = g.Select(x => x.Plot.Name).FirstOrDefault(), Trees = g.Sum(t => t.TreesNumber), Volume = g.Sum(t => t.Volume), Loyality = g.Sum(t => t.Loyality), TFF = g.Sum(t => t.TFF), LMDA = g.Sum(t => t.LMDA), CESS = g.Sum(t => t.CESS), VAT = g.Sum(t => t.VAT), TP = g.Sum(t => t.TP), TOTAL = g.Sum(t => t.TOTAL) } ).ToList(); return(plots); }
public void UpdateDealer(DealerDto input) { var dealer = _dealerRepository.FirstOrDefault(input.Id); dealer.IsSubmitted = input.IsSubmitted; _dealerRepository.Update(dealer); }
public async Task DeleteDealerAsync(DealerDto input) { var dealer = _dealerRepository.FirstOrDefault(input.Id); if (dealer == null) { throw new UserFriendlyException("Dealer Year not Found!"); } await _dealerRepository.DeleteAsync(dealer); }
/// <inheritdoc/> public void CreateDealer(IDealer dealer) { DealerDto dealerDto = DealerDto.ToDto(dealer); this.Context.Dealers.Add(dealerDto); int count = this.Context.SaveChanges(); if (count != 1) { throw new ApplicationException($"Unexpectedly created {count} rows"); } }
public IActionResult UpdateDealer([FromBody] DealerDto dealerDto, int dealerId) { if (ModelState.IsValid) { var dealerToUpdate = _mapper.Map <Dealer>(dealerDto); _dealerRepo.Update(dealerToUpdate, dealerId); return(Ok("Dealer updated correctly.")); } else { return(BadRequest("ModelState is not valid.")); } }
public IActionResult CreateDealer([FromBody] DealerDto dealerDto) { if (ModelState.IsValid) { var dealerToCreate = _mapper.Map <Dealer>(dealerDto); var create = _dealerRepo.Create(dealerToCreate); return(Created($"https://localhost:5001/dealer/{create.Id}", create)); } else { return(BadRequest("ModelState is not valid")); } }
public void UpdateBillControlNumber(DealerDto input, string BillControlNumber) { var dealer = _dealerRepository.FirstOrDefault(input.Id); if (dealer != null) { dealer.BillControlNumber = BillControlNumber; _dealerRepository.UpdateAsync(dealer); } else { throw new UserFriendlyException("Dealer not Found!"); } }
public IHttpActionResult CreateDealer(DealerDto dealerDto) { if (!ModelState.IsValid) { return(BadRequest()); } var dealer = Mapper.Map <DealerDto, Dealer>(dealerDto); _context.Dealers.Add(dealer); _context.SaveChanges(); dealerDto.Id = dealer.Id; return(Created(new Uri(Request.RequestUri + "/" + dealer.Id), dealerDto)); }
//approve application for registration public int ApproveRegistration(DealerDto input) { var dealer = _dealerRepository.FirstOrDefault(input.Id); if (dealer != null && dealer.IsSubmitted == true) { dealer.IsApproved = true; dealer.ApprovedUserId = (int)AbpSession.UserId; dealer.Remark = input.Remark; return(_dealerRepository.InsertOrUpdateAndGetId(dealer)); } else { throw new UserFriendlyException("Application for Registration not Found!"); } }
public ActionResult DenyRegistration(DealerDto input) { var dealer = _dealerAppService.GetDealer(input.Id); var DealerActivities = _dealerActivityAppService.GetDealerActivities(dealer); if (input.Remark != null && dealer != null) { _dealerAppService.DenyRegistration(input); TempData["success"] = string.Format(@"The application has been rejected!"); return(RedirectToAction("OnlineRegApplications")); } else { ViewBag.DealerActivities = DealerActivities; TempData["danger"] = string.Format(@"Failed to reject the selected application, remarks field should not be empty!"); return(View(dealer)); } }
// PUT api/dealers/1 public IHttpActionResult UpdateDealer(int id, DealerDto dealerDto) { if (!ModelState.IsValid) { return(BadRequest()); } var dealerInDb = _context.Dealers.SingleOrDefault(c => c.Id == id); if (dealerInDb == null) { return(NotFound()); } Mapper.Map(dealerDto, dealerInDb); _context.SaveChanges(); return(Ok()); }
//Deny Registration public void DenyRegistration(DealerDto input) { var dealer = _dealerRepository.FirstOrDefault(input.Id); if (dealer != null && dealer.IsSubmitted == true) { dealer.IsApproved = false; dealer.IsDenied = true; dealer.ApprovedUserId = (int)AbpSession.UserId; dealer.Remark = input.Remark; _dealerRepository.Update(dealer); } else { throw new UserFriendlyException("Application for Registration not Found!"); } }
public ActionResult ApproveRegistration(DealerDto input) { double TotalBillAmount = 0; try { var dealer = _dealerAppService.GetDealer(input.Id); var DealerActivities = _dealerActivityAppService.GetDealerActivities(dealer); if (input.Remark != null && dealer != null) { int dealerId = _dealerAppService.ApproveRegistration(dealer); foreach (var activity in DealerActivities) { TotalBillAmount = TotalBillAmount + activity.Activity.Fee + activity.Activity.RegistrationFee; } DateTime billExpireDate = DateTime.Now; billExpireDate = billExpireDate.AddDays(30); var RegistrationBill = new CreateBillInput { ApplicantId = dealer.ApplicantId, StationId = dealer.StationId, FinancialYearId = dealer.FinancialYearId, BillAmount = TotalBillAmount, EquvAmont = TotalBillAmount, Description = "Application For Registration Fee", ExpiredDate = billExpireDate, Currency = "TZS" }; int bill = _billAppService.CreateBill(RegistrationBill); // create bill foreach (var activity in DealerActivities) /// add Bill Items { CreateBillItemInput item = new CreateBillItemInput { BillId = bill, ActivityId = activity.ActivityId, Description = activity.Activity.Description, Loyality = activity.Activity.Fee + activity.Activity.RegistrationFee, EquvAmont = activity.Activity.Fee + activity.Activity.RegistrationFee, }; _billItemAppService.CreateBillItem(item); } TempData["success"] = string.Format(@"The application has been approved successfully!"); return(RedirectToAction("OnlineRegApplications")); } else { ViewBag.DealerActivities = DealerActivities; TempData["danger"] = string.Format(@"Failed to reject the selected application, remarks field should not be empty!"); return(View(dealer)); } } catch { TempData["danger"] = string.Format(@"Failed to approve the selected application!"); return(RedirectToAction("OnlineRegApplications")); } }
//Pre selected dealer's allocated volume public double DealerAllocatedCBM(DealerDto input) { var dealer = _dealerRepository.FirstOrDefault(input.Id); return(99); }