protected void btnAddDiscount_Click(object sender, EventArgs e) { DateTime dt; obj = new DiscountMaster(); obj.Name = txtName.Text; obj.Description = txtDescription.Text; obj.Percentage = Convert.ToDouble('0' + txtPercentage.Text); if (DateTime.TryParseExact(txtValidFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { obj.ValidFrom = dt; } if (DateTime.TryParseExact(txtValidTo.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { obj.ValidTo = dt; } //obj.IsVisible = chkVisible.Checked; obj.CreatedBy = 1; obj.UpdatedBy = 1; obj.DiscountID = Convert.ToInt16(lblDiscountID.Text); if (lblDiscountID.Text.Equals("-1")) { obj1 = new DiscountMasterDataManager(); obj1.AddDiscountDetail(obj); msgbox("Discount Added successfully!!!"); } else { obj1 = new DiscountMasterDataManager(); obj1.UpdateDiscountDetail(obj); msgbox("Discount updated successfully!!!"); } Clear(); bind(); }
public void AddDiscountDetail(DiscountMaster obj) { try { SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@Name", obj.Name), new SqlParameter("@Description", obj.Description), new SqlParameter("@Percentage", obj.Percentage), new SqlParameter("@ValidFrom", obj.ValidFrom), new SqlParameter("@ValidUpto", obj.ValidTo), // new SqlParameter("@IsVisible",obj.IsVisible.Equals(true)?1:0), new SqlParameter("@CreatedBy", obj.CreatedBy), new SqlParameter("@UpdatedBy", obj.UpdatedBy) }; DBOperate.ExecuteProcedureWithOutReturn("usp_AddDiscount", parameter); } catch { throw; } }
public void Create(DiscountMaster discount) { _DiscountMasterRepository.Add(discount); _unitOfWork.Commit(); }
public async Task <ResponseStatus> addDiscount(discountRequest discountRequest) { ResponseStatus response = new ResponseStatus(); try { if (discountRequest.id == "0") { var id = Guid.NewGuid(); DiscountMaster discountMaster = new DiscountMaster { id = id.ToString(), vendorid = discountRequest.vendorid, title = discountRequest.title, discounton = discountRequest.discounton, type = discountRequest.type, couponcode = discountRequest.couponcode, couponmaxuse = discountRequest.couponmaxuse, discountper = discountRequest.discountper, discountamt = discountRequest.discountamt, maxdiscountamt = discountRequest.maxdiscountamt, fromdate = discountRequest.fromdate, todate = discountRequest.todate, // menuspecific= discountRequest.menuspecific, //userspecifics= discountRequest.userspecifics, conditionaldiscount = discountRequest.conditionaldiscount, mindiscountamt = discountRequest.mindiscountamt, status = discountRequest.status, createdAt = DateTime.Now, deleted = false }; appDbContex.DiscountMasters.Add(discountMaster); await appDbContex.SaveChangesAsync(); for (int i = 0; i < discountRequest.discountMenuSpecifics.Count; i++) { var dmid = Guid.NewGuid(); DiscountMenuSpecific discountMenuSpecific = new DiscountMenuSpecific { id = dmid.ToString(), discountid = id.ToString(), vendorid = discountRequest.vendorid, productid = discountRequest.discountMenuSpecifics[i].id, name = discountRequest.discountMenuSpecifics[i].name }; appDbContex.DiscountMenuSpecifics.Add(discountMenuSpecific); await appDbContex.SaveChangesAsync(); } for (int i = 0; i < discountRequest.discountUserSpecifics.Count; i++) { var dmid = Guid.NewGuid(); DiscountUserSpecific discountUserSpecific = new DiscountUserSpecific { id = dmid.ToString(), discountid = id.ToString(), vendorid = discountRequest.discountUserSpecifics[i].vendorid, PhoneNumber = discountRequest.discountUserSpecifics[i].PhoneNumber, name = discountRequest.discountUserSpecifics[i].name }; appDbContex.DiscountUserSpecifics.Add(discountUserSpecific); await appDbContex.SaveChangesAsync(); } response.status = true; response.message = "Discount details added successfully."; response.objItem = id; return(response); } else { var discount = appDbContex.DiscountMasters.Where(a => a.id == discountRequest.id).SingleOrDefault(); if (discount != null) { discount.vendorid = discountRequest.vendorid; discount.title = discountRequest.title; discount.discounton = discountRequest.discounton; discount.type = discountRequest.type; discount.couponcode = discountRequest.couponcode; discount.couponmaxuse = discountRequest.couponmaxuse; discount.discountper = discountRequest.discountper; discount.discountamt = discountRequest.discountamt; discount.maxdiscountamt = discountRequest.maxdiscountamt; discount.fromdate = discountRequest.fromdate; discount.todate = discountRequest.todate; // discount.menuspecific = discountRequest.menuspecific; // discount.userspecifics = discountRequest.userspecifics; discount.conditionaldiscount = discountRequest.conditionaldiscount; discount.mindiscountamt = discountRequest.mindiscountamt; discount.status = discountRequest.status; discount.createdAt = DateTime.Now; discount.deleted = false; await appDbContex.SaveChangesAsync(); var discountmenu = appDbContex.DiscountMenuSpecifics.Where(a => a.discountid == discountRequest.id).ToList(); if (discountmenu != null) { foreach (var ls in discountmenu) { appDbContex.DiscountMenuSpecifics.Remove(ls); await appDbContex.SaveChangesAsync(); } } var discountuser = appDbContex.DiscountUserSpecifics.Where(a => a.discountid == discountRequest.id).ToList(); if (discountuser != null) { foreach (var ls in discountuser) { appDbContex.DiscountUserSpecifics.Remove(ls); await appDbContex.SaveChangesAsync(); } } for (int i = 0; i < discountRequest.discountMenuSpecifics.Count; i++) { var dmid = Guid.NewGuid(); DiscountMenuSpecific discountMenuSpecific = new DiscountMenuSpecific { id = dmid.ToString(), discountid = discountRequest.id.ToString(), vendorid = discountRequest.vendorid, productid = discountRequest.discountMenuSpecifics[i].id, name = discountRequest.discountMenuSpecifics[i].name }; appDbContex.DiscountMenuSpecifics.Add(discountMenuSpecific); await appDbContex.SaveChangesAsync(); } for (int i = 0; i < discountRequest.discountUserSpecifics.Count; i++) { var dmid = Guid.NewGuid(); DiscountUserSpecific discountUserSpecific = new DiscountUserSpecific { id = dmid.ToString(), discountid = discountRequest.id.ToString(), vendorid = discountRequest.discountUserSpecifics[i].id, PhoneNumber = discountRequest.discountUserSpecifics[i].PhoneNumber, name = discountRequest.discountUserSpecifics[i].name }; appDbContex.DiscountUserSpecifics.Add(discountUserSpecific); await appDbContex.SaveChangesAsync(); } response.status = true; response.objItem = discountRequest.id; response.message = "Discount details Updated Successfully!"; return(response); } } return(response); } catch (Exception ex) { throw ex; } }