public IActionResult Create(string flyerCategory) { var flyerCate = _flyerCategoryRepository.GetByCondition(c => c.Name == flyerCategory).FirstOrDefault(); var linkFlyers = Helper.FlyerLink.GetLink(flyerCategory); foreach (var link in linkFlyers) { var merchantCode = Helper.FlyerLink.MerchantCode(link); var merchant = _merchantRepository.GetByCondition(m => m.MerchantCode == merchantCode).FirstOrDefault(); if (merchant == null) { merchant = new Merchant { MerchantCode = merchantCode }; _merchantRepository.Add(merchant); } var flyer = new Flyer { Url = link, FlyerCategoryId = flyerCate.Id, FlyerCategory = flyerCate, MerchantId = merchant.Id, Merchant = merchant, IsActive = true }; if (!_flyerRepository.IsExist(f => f.Url == link)) { _flyerRepository.Add(flyer); } } return(RedirectToAction("Index")); }
private void SetupInitialTestData(IMerchantRepository merchantRepository) { var newMerchant = new Merchant() { MerchantId = "TEST", FullName = "bob", AccountNumber = "1111111111111111", SortCode = "111111", CardNumber = "1234123412341234", Csv = "234" }; merchantRepository.Add(newMerchant).Wait(); merchantRepository.Save().Wait(); }
public async Task <Merchant> Add(Merchant merchant) { var dbMerchant = await _merchantRepository.Get(merchant.Name); if (dbMerchant != null) { throw new BusinessException( BusinessExceptionCodes.MerchantAlreadyExists, $"Merchant {merchant.Name} already exists"); //TODO: Move this to a resource file. } merchant.Id = Guid.NewGuid(); return(await _merchantRepository.Add(merchant)); }
public ActionResult Create(string url) { if (!ModelState.IsValid) { return(View(url)); } else { var flyerViewModel = new FlyerViewModel { Url = url }; if (!_flyerRepository.IsExist(f => f.Url == url)) { var crawlObject = Function.GetAllCrawlModels(url); var merchant = new Merchant { Name = crawlObject.merchant, Url = crawlObject.merchant_url, LogoFile = crawlObject.merchant_logo }; if (!_merchantRepository.IsExist(m => m.Name == merchant.Name)) { _merchantRepository.Add(merchant); } else { merchant = _merchantRepository.GetByCondition(m => m.Name == merchant.Name).FirstOrDefault(); } foreach (var crawlcate in crawlObject.categories) { var category = new Category(); category.Name = crawlcate.name; if (!_categoryReposity.IsExist(c => c.Name == category.Name)) { _categoryReposity.Add(category); } else { category = _categoryReposity.GetByCondition(c => c.Name == category.Name).FirstOrDefault(); } var merchantCategory = new MerchantCategory { Merchant = merchant, Category = category }; var exist = _merchantCategoryRepo.GetByCondition(c => c.Category == category & c.Merchant == merchant).Count > 0 ? true : false; if (!exist) { _merchantCategoryRepo.Add(merchantCategory); merchant.MerchantCategories.Add(merchantCategory); category.MerchantCategories.Add(merchantCategory); } } foreach (var item in crawlObject.items) { if (item.current_price != null) { var product = new Product { Name = item.name, CurrentPrice = Convert.ToDecimal(item.current_price), Brand = item.brand, Description = item.description, Discount_percent = item.discount_percent.ToString(), DisplayName = item.display_name, Dist_coupon_image_url = item.dist_coupon_image_url, Image = item.large_image_url, Url = item.url, InStoreOnly = item.in_store_only, X_large_image_url = item.x_large_image_url, Sale_Story = item.sale_story, Item_Id = item.flyer_item_id, Valid_from = DateTime.Parse(item.valid_from), Valid_to = DateTime.Parse(item.valid_to) }; if (item.category_names.Count > 0) { var cate = item.category_names[0]; var proCate = _categoryReposity.GetByCondition(c => c.Name == cate).FirstOrDefault(); if (proCate == null) { proCate = new Category(); proCate.Name = cate; _categoryReposity.Add(proCate); } var merchantCategory = new MerchantCategory { Merchant = merchant, Category = proCate }; var exist = _merchantCategoryRepo.GetByCondition(c => c.Category == proCate & c.Merchant == merchant).Count > 0 ? true : false; if (!exist) { _merchantCategoryRepo.Add(merchantCategory); merchant.MerchantCategories.Add(merchantCategory); proCate.MerchantCategories.Add(merchantCategory); } product.Category = proCate; } if (!_productRepository.IsExist(p => p.Item_Id == product.Item_Id)) { _productRepository.Add(product); if (!merchant.Products.Contains(product)) { merchant.Products.Add(product); } } } } _merchantRepository.Update(merchant); var flyer = new Flyer { Url = url, Valid_from = crawlObject.valid_from, Valid_to = crawlObject.valid_to }; _flyerRepository.Add(flyer); } } return(View()); }
public object Save(bool isEditMode, string evnt, Reginfo regInfo) { try { if (isEditMode != true) { var reginfoModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); if (reginfoModel == null) { regInfo.RegSource = "P"; regInfo.AcTypeCode = 1; //regInfo.RegDate = regInfo.RegDate + DateTime.Now.TimeOfDay; regInfo.RegDate = System.DateTime.Now; regInfo.EntryDate = System.DateTime.Now; var currentMcode = _MerchantRepository.GenerateMerchantCode(regInfo._MCategory); var Heading = ((IDictionary <string, object>)currentMcode).Keys.ToArray(); var details = ((IDictionary <string, object>)currentMcode); var values = details[Heading[0]]; var mcode = values; if (!string.IsNullOrEmpty(mcode.ToString())) { regInfo._Mcode = mcode.ToString(); } if (regInfo.SelectedCycleWeekDay != null) { regInfo.SelectedCycleWeekDay = string.Join(",", regInfo._SelectedCycleWeekDay); } MerchantConfig merchantConfig = new MerchantConfig(); if (regInfo._MCategory == "EMSM" || regInfo._MCategory == "EMSC") { merchantConfig.Sname = "EMS." + regInfo._OrgCode; merchantConfig.Ci = "CUSTOMER_SERVICE_CHARGE_MIN"; merchantConfig.PreFuncProcName = "PROC_COMMUNICATOR_EMS"; merchantConfig.Di = "CUSTOMER_SERVICE_CHARGE_MAX"; merchantConfig.SchargeFormula = "FUNC_CHECK_MIN_MAX_CHARGE(:A*:B,:C,:D)"; merchantConfig.PostFuncProcName = "PROC_REMOVE_LIEN"; merchantConfig.Category = "S"; regInfo.CatId = regInfo._MCategory; } else if (regInfo._MCategory == "MMSM" || regInfo._MCategory == "MMSC") { merchantConfig.Sname = "MMS." + regInfo._OrgCode; merchantConfig.Ci = "CUSTOMER_SERVICE_CHARGE_MIN"; merchantConfig.PreFuncProcName = "PROC_COMMUNICATOR_MMS"; merchantConfig.Di = "CUSTOMER_SERVICE_CHARGE_MAX"; merchantConfig.SchargeFormula = "FUNC_CHECK_MIN_MAX_CHARGE(:A*:B,:C,:D)"; merchantConfig.PostFuncProcName = "PROC_REMOVE_LIEN"; merchantConfig.Category = "S"; regInfo.CatId = regInfo._MCategory; } else if (regInfo._MCategory == "ABM") { if (string.IsNullOrEmpty(regInfo.Pmphone)) { return(HttpStatusCode.BadRequest);; } merchantConfig.Sname = null; merchantConfig.Ci = null; merchantConfig.PreFuncProcName = null; merchantConfig.Di = null; merchantConfig.SchargeFormula = null; merchantConfig.PostFuncProcName = null; merchantConfig.Category = "B"; regInfo.CatId = regInfo._MCategory; if (regInfo.SchargePer > 0) { double?serviceCharge = regInfo.SchargePer; regInfo.SchargePer = serviceCharge / 100; } } else { merchantConfig.Sname = null; merchantConfig.Ci = null; merchantConfig.PreFuncProcName = null; merchantConfig.Di = null; merchantConfig.SchargeFormula = null; merchantConfig.PostFuncProcName = null; merchantConfig.Category = regInfo._MCategory; regInfo.CatId = "M"; } merchantConfig.Mcode = regInfo._Mcode; merchantConfig.Mphone = regInfo.Mphone; try { _merchantConfigService.Add(merchantConfig); _kycService.InsertModelToAuditTrail(merchantConfig, regInfo.EntryBy, 5, 3, "Merchant Config", merchantConfig.Mphone, "Save successfully"); _MerchantRepository.Add(regInfo); _kycService.InsertModelToAuditTrail(regInfo, regInfo.EntryBy, 5, 3, "Merchant", regInfo.Mphone, "Merchant added"); } catch (Exception ex) { throw ex; } return(HttpStatusCode.OK); } else { return(HttpStatusCode.BadRequest); } } else { if (evnt == "edit") { if (regInfo._SelectedCycleWeekDay != null) { regInfo.SelectedCycleWeekDay = string.Join(",", regInfo._SelectedCycleWeekDay); } regInfo.UpdateDate = System.DateTime.Now; var prevModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); _MerchantRepository.UpdateRegInfo(regInfo); var currentModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); _kycService.InsertUpdatedModelToAuditTrail(currentModel, prevModel, regInfo.UpdateBy, 5, 4, "Merchant", regInfo.Mphone, "Merchant updated"); return(HttpStatusCode.OK); } else { var checkStatus = _kycService.CheckPinStatus(regInfo.Mphone); if (checkStatus.ToString() != "P") { regInfo.RegStatus = "P"; regInfo.PinStatus = "Y"; regInfo.AuthoDate = System.DateTime.Now; //regInfo.RegDate = _kycService.GetRegDataByMphoneCatID(regInfo.Mphone, "M"); var prevModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); _MerchantRepository.UpdateRegInfo(regInfo); var currentModel = _kycService.GetRegInfoByMphone(regInfo.Mphone); _kycService.InsertUpdatedModelToAuditTrail(currentModel, prevModel, regInfo.AuthoBy, 5, 4, "Merchant", regInfo.Mphone, "Register successfully"); int fourDigitRandomNo = new Random().Next(1000, 9999); _MerchantRepository.UpdatePinNo(regInfo.Mphone, fourDigitRandomNo.ToString()); MessageService service = new MessageService(); service.SendMessage(new MessageModel() { Mphone = regInfo.Mphone, MessageId = "999", MessageBody = "Congratulations! Your OK wallet has been opened successfully." + " Your Pin is " + fourDigitRandomNo.ToString() + ", please change PIN to activate your account, " }); return(HttpStatusCode.OK); } else { return(HttpStatusCode.OK); } } } } catch (Exception ex) { throw ex; } }