public async Task <HttpResponseMessage> SavePartnerAsync([FromBody] PartnerModel partner) { var branches = PartnerMapper.MapToBranches(partner, _imageConverter); var partnerBranches = await _partnerApplicationService.GetPartnerDetailsAsync(partner.Id); var newPartner = new Branch(); newPartner = branches.ElementAt(0).PartnerId != null?branches.First(x => x.Id == x.PartnerId) : branches.ElementAt(0); var partnerFirst = await _partnerApplicationService.UpsertPartnerAsync(newPartner); foreach (var branch in branches.Where(b => b.Id != b.PartnerId || (b.Id == null && b.PartnerId == null))) { branch.PartnerId = partnerFirst.PartnerId; var qwerty = await _partnerApplicationService.UpsertBranchAsync(branch); } foreach (var branch in partnerBranches) { if (branches.FirstOrDefault(x => x?.Id == branch.Id) == null) { await _partnerApplicationService.DeleteBranchAsync(branch.Id); } } return(new HttpResponseMessage(HttpStatusCode.OK)); }
public ActionResult GetPartnerById(string id) { _logger.LogInformation("Getting a partners"); var partners = _partnerService.GetById(id); var partnerModels = PartnerMapper.SerializePartner(partners); return(Ok(partnerModels)); }
public ActionResult CreatePartner([FromBody] PartnerModel partner) { _logger.LogInformation("Adding a new partner"); var partnerData = PartnerMapper.SerializePartner(partner); var newPartner = _partnerService.CreatePartner(partnerData); return(Ok(newPartner)); }
public void MapToPartnerModelTestMethod() { // Arrange var branches = CreateBranches(); // Act var resultPartnerModel = PartnerMapper.Map(branches, _categoryModels); var firstBranch = branches.First(); // Assert Assert.AreEqual(resultPartnerModel.Id, firstBranch.PartnerId); Assert.AreEqual(resultPartnerModel.Discount, double.Parse(firstBranch.Discounts.First().Name.First().LocText)); Assert.AreEqual(resultPartnerModel.SelectDiscount, firstBranch.Discounts.First().DiscountType); Assert.AreEqual(resultPartnerModel.Comment, firstBranch.Comment); Assert.AreEqual(resultPartnerModel.Description_En, firstBranch.Description.First(x => x.Lan == Languages.En).LocText); Assert.AreEqual(resultPartnerModel.Description_Ru, firstBranch.Description.First(x => x.Lan == Languages.Ru).LocText); Assert.AreEqual(resultPartnerModel.Image, firstBranch.Image); Assert.AreEqual(resultPartnerModel.Logo, firstBranch.Icon); Assert.AreEqual(resultPartnerModel.Name_En, firstBranch.Name.First(x => x.Lan == Languages.En).LocText); Assert.AreEqual(resultPartnerModel.Name_Ru, firstBranch.Name.First(x => x.Lan == Languages.Ru).LocText); AssertCategories(resultPartnerModel.Categories, firstBranch.CategoryIds); AssertWebAddresses(resultPartnerModel.WebAddresses?.ToList(), firstBranch.WebAddresses?.ToList()); for (var i = 0; i < branches.Count; i++) { var branch = branches[i]; var contact = resultPartnerModel.Contacts?.ToList()[i]; AssertAddress(contact, branch.Address?.ToList()); } for (var i = 0; i < branches.Count; i++) { var branch = branches[i]; var contact = resultPartnerModel.Contacts?.ToList()[i]; AssertPhones(contact, branch.Phones?.ToList()); } for (var i = 0; i < branches.Count; i++) { var branch = branches[i]; var contact = resultPartnerModel.Contacts?.ToList()[i]; AssertCoordinates(contact, branch.Location); } for (var i = 0; i < branches.Count; i++) { var branch = branches[i]; var contact = resultPartnerModel.Contacts?.ToList()[i]; AssertId(contact, branch.Id); } }
public ActionResult UpdatePartner([FromBody] PartnerModel partner) { _logger.LogInformation("Update partner complete..."); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var partnerData = PartnerMapper.SerializePartner(partner); var response = _partnerService.UpdatePartner(partnerData); return(Ok(response)); }
public async Task <ActionResult> PostAsync([FromBody] GalleryImageModel model) { string result; if (ModelState.IsValid) { var galleryImage = PartnerMapper.MapToGalleryImage(model, _imageConverter); result = await _galleryService.AddGalleryImageToPartnerAsync(galleryImage); } else { return(BadRequest()); } return(new JsonResult(new { id = result })); }
public async Task <PartnerModel> GetPartnerDetailsAsync(string partnerId) { var categories = await _categoryApplicationService.GetCategoryListAsync(); var categoriesModels = CategoryMapper.MapToCategoryModels(categories); var partnerBranches = await _partnerApplicationService.GetPartnerDetailsAsync(partnerId); var partnerGalleryImages = await _galleryService.GetGalleryImageIdsForPartner(partnerId); var rating = (await _ratingService.GetPartnerRatingAsync(partnerId)).MapToPartnerStatisticsModel(); var partner = PartnerMapper.Map( partnerBranches?.ToList(), categoriesModels?.ToArray(), partnerGalleryImages?.ToList(), rating); return(partner); }
private void tPartner_MouseClick(object sender, MouseEventArgs e) { SelectedPartnerId = PartnerMapper.SelectPartnerId(Supplier: true); tPartner.Text = Sql.GetString($"SELECT dbo.GetPartnerName('{SelectedPartnerId}')"); }
private void TSupplier_GotFocus(object sender, EventArgs e) { SelectedPartnerId = PartnerMapper.SelectPartnerId(Customer: true); tCustomer.Text = Sql.GetString($"SELECT dbo.GetPartnerName('{SelectedPartnerId}')"); }
public PartnerController() { this._service = new PartnerService(); this._mapper = new PartnerMapper(); }