public Enrollment Promote(PromotionDTO promotion) { using (SqlConnection connection = new SqlConnection(CONNECTION_STRING)) using (SqlCommand command = new SqlCommand()) { try { command.Connection = connection; connection.Open(); command.CommandText = "PromoteStudent"; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("Semester", promotion.Semester); command.Parameters.AddWithValue("Study", promotion.Studies); SqlDataReader dataReader = command.ExecuteReader(); if (dataReader.Read()) { int semester = dataReader.GetInt32(0); Study study = Study.newStudy(dataReader.GetString(1)); DateTime dateTime = Convert.ToDateTime(dataReader.GetDateTime(2)); return(Enrollment.newEnrollment(semester, study, dateTime)); } return(null); } catch (Exception ex) { Console.WriteLine(ex); return(null); } } }
public IActionResult UpsertPromotion(PromotionDTO promotionDTO) { var promotion = _context.Promotion.FirstOrDefault(it => it.Name == promotionDTO.Name); var isInsert = promotion == null; if (isInsert) { promotion = new Promotion(); } promotion.MinPrice = promotionDTO.MinPrice; promotion.Name = promotionDTO.Name; promotion.PromotionTypeName = promotionDTO.PromotionType; if (isInsert) { _context.Promotion.Add(promotion); } else { _context.Promotion.Update(promotion); } try { _context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); return(BadRequest(e.Message)); } return(Ok()); }
public void Initialize() { _uow = A.Fake<IUnitOfWork>(); _mapper = A.Fake<IMappingEngine>(); _service = new PromotionService(_uow, _mapper); _nonExistingPromotion = new Promotion(); _existingPromotion = new Promotion(); _promotionWithNoPayments = new Promotion(); _promotionWithPayments = new Promotion(); _nonExistingPromotionDTO = new PromotionDTO(); _existingPromotionDTO = new PromotionDTO(); _promotionWithNoPaymentsDTO = new PromotionDTO(); _promotionWithPaymentsDTO = new PromotionDTO(); A.CallTo(() => _mapper.Map<Promotion>(_nonExistingPromotionDTO)).Returns(_nonExistingPromotion); A.CallTo(() => _mapper.Map<Promotion>(_existingPromotionDTO)).Returns(_existingPromotion); A.CallTo(() => _mapper.Map<Promotion>(_promotionWithNoPaymentsDTO)).Returns(_promotionWithNoPayments); A.CallTo(() => _mapper.Map<Promotion>(_promotionWithPaymentsDTO)).Returns(_promotionWithPayments); A.CallTo(() => _uow.PromotionRepository.IsExisting(_nonExistingPromotion)).Returns(false); A.CallTo(() => _uow.PromotionRepository.IsExisting(_existingPromotion)).Returns(true); A.CallTo(() => _uow.PromotionRepository.HasPayments(_promotionWithPayments)).Returns(true); A.CallTo(() => _uow.PromotionRepository.HasPayments(_promotionWithNoPayments)).Returns(false); }
protected void btnAdd_Click(object sender, EventArgs e) { if (!lblCode.Text.Equals("Promotion code will appear here!")) { PromotionDTO dto = new PromotionDTO { Code = lblCode.Text, Name = txtName.Text.Trim(), Active = true }; try { if (dao.AddPromotion(dto)) { SetMessageTextAndColor("Successfully Added", Color.Green); } else { SetMessageTextAndColor("Failed to add", Color.Red); } } catch { SetMessageTextAndColor("Code has already been added please generate a different one.", Color.Red); } } }
public async Task <IActionResult> EditPromotion([FromBody] PromotionDTO model) { var email = (await _userManager.GetUserAsync(HttpContext.User)).Email; var user = await _userRepository.FindByEmail(email); var business = user.Business; if (business == null) { return(Unauthorized()); } if (business.Promotions == null) { new Exception("Promotielijst is leeg, er kan niets worden aangepast."); } var editPromotion = await _promotionRepository.FindById(model.Id); editPromotion.Name = model.Name; editPromotion.Description = model.Description; editPromotion.PromotionType = model.PromotionType; editPromotion.EndDate = model.EndDate; editPromotion.StartDate = model.StartDate; await _promotionRepository.SaveChanges(); return(Ok()); }
public async Task AddUpdatePromotion(PromotionDTO item, object Id) { var rest = await FirstOrDefaultAsync(x => x.Id == (string.IsNullOrEmpty((string)Id) ? new ObjectId() : new ObjectId((string)Id))); if (rest == null) { throw new HttpStatusCodeException(StatusCodes.Status404NotFound, "Restaurant Bulunumadı..!!"); } bool isNew = false; var pro = rest.Promotion.FirstOrDefault(x => x.Id == (string.IsNullOrEmpty((string)item.Id) ? new ObjectId() : new ObjectId((string)item.Id))); if (pro == null) { isNew = true; pro = new Promotion(); } if (isNew) { rest.Promotion.Add(new Promotion() { Claim = item.Claim, Id = ObjectId.GenerateNewId(), ProductId = new ObjectId((string)item.ProductId), Status = item.Status }); } else { pro.Claim = item.Claim; pro.ProductId = new ObjectId((string)item.ProductId); pro.Status = item.Status; } await UpdateAsync(rest); }
public PromotionDTO AddNewPromotion(PromotionDTO promotionDTO) { var newPromotion = _promotionFactory.Create(promotionDTO); _uow.Promotions.Add(newPromotion); _uow.SaveChanges(); return(_promotionFactory.CreateComplex(newPromotion)); }
public IActionResult Promotions(PromotionDTO promo) { if (_dbService.promo(promo)) { return(Ok()); } return(BadRequest()); }
/// <summary> /// 修改操作 /// </summary> public void Updates(PromotionDTO promotionDTO) { Promotion promotion = new Promotion().FromEntityData(promotionDTO); ContextSession contextSession = ContextFactory.CurrentThreadContext; promotion.EntityState = System.Data.EntityState.Modified; contextSession.SaveObject(promotion); contextSession.SaveChanges(); }
public Promotion Create(PromotionDTO promotionDTO) { return(new Promotion { PromotionId = promotionDTO.PromotionId, Name = promotionDTO.Name, Description = promotionDTO.Description, Type = promotionDTO.Type, ValidTo = promotionDTO.ValidTo }); }
public Promotion getEntity(PromotionDTO dto) { Promotion promotion = new Promotion(); promotion.PromotionId = dto.PromotionId; promotion.ProductId = dto.ProductId; promotion.Quantity = dto.Quantity; promotion.Discount = dto.Discount; promotion.Timestamp = dto.Timestamp; return(promotion); }
public PromotionDTO getDTO(Promotion promotion) { PromotionDTO dto = new PromotionDTO(); dto.PromotionId = promotion.PromotionId; dto.ProductId = promotion.ProductId; dto.Quantity = promotion.Quantity; dto.Discount = promotion.Discount; dto.Timestamp = promotion.Timestamp; return(dto); }
public void Add(PromotionDTO entity) { Promotion promotion = _mapper.Map<Promotion>(entity); if (isExisting(promotion)) { throw new PromotionAlreadyExistsException(Properties.Resources.PromotionAlreadyExistsExceptionText); } _unitOfWork.PromotionRepository.Add(promotion); _unitOfWork.Commit(); }
public void Delete(PromotionDTO entity) { Promotion promotion = _mapper.Map<Promotion>(entity); if (hasPayments(promotion)) { throw new PromotionHasPaymentException(Properties.Resources.PromotionHasPaymentsExceptionText); } _unitOfWork.PromotionRepository.Delete(promotion); _unitOfWork.Commit(); }
public async Task <IActionResult> Create(PromotionFormModel model) { try { FillPromotionFormModel(model); if (!this.ModelState.IsValid) { return(this.View((object)model)); } if (!DateTime.TryParseExact(model.DueDateStr, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime result)) { model.IsSuccess = false; model.FormMessage = "Geçerli bir tarih giriniz."; return(this.View((object)model)); } model.DueDate = result; if (model.DueDate < DateTime.Today) { model.IsSuccess = false; model.FormMessage = "Son kullanım tarihi bugünden önce olamaz."; return(this.View((object)model)); } PromotionDTO promotionDTO = new PromotionDTO { IsActive = true, Message = model.Message, DueDate = model.DueDate, UserId = model.UserId, PlaceId = model.PlaceId, CreatedBy = base.CurrentUser.FullName }; if (base.CurrentUser.Role == UserRole.Dealer) { model.PlaceId = (base.CurrentUser.PlaceId ?? 0); } Result <PromotionDTO> result2 = await _promotionService.AddPromotionAsync(promotionDTO); model.FormMessage = result2.FormMessage; model.IsSuccess = result2.IsSuccess; if (model.IsSuccess) { model.FormMessage = "İşleminiz başarılı bir şekilde gerçekleştirildi."; } return(this.View((object)model)); } catch (Exception ex) { LoggerExtensions.LogError(_logger, ex, "Create Error", Array.Empty <object>()); model.IsSuccess = false; model.FormMessage = "İşleminiz gerçekleştirilemedi."; return(this.View((object)model)); } }
public IActionResult PostPromotion([FromBody] PromotionDTO promotionDTO) { _requestLogService.SaveRequest(User.Identity.GetUserId(), "POST", "api/v1/promotions", "PostPromotion"); if (!ModelState.IsValid) { return(BadRequest("Invalid fields provided, please double check the parameters")); } var newPromotion = _promotionService.AddNewPromotion(promotionDTO); return(CreatedAtAction(nameof(GetPromotion), new { id = newPromotion.PromotionId }, newPromotion)); }
public IActionResult Update([FromServices] ICacheHelper cache, int id, PromotionDTO promotionDTO) { if (id <= 0 || !ModelState.IsValid) { return(BadRequest(new { message = "ID is invalid" })); } if (!_promModel.UpdateDTO(id, promotionDTO, promotionDTO.ItemDetail)) { return(Problem(statusCode: 500, detail: "Can't update data")); } cache.DataUpdated(CacheKey.PRODUCT); cache.DataUpdated(CacheKey.DISCOUNT_PRODUCT); return(Ok()); }
public PromotionDTO addPromotion(PromotionDTO promotion) { if (promotionDataAccessProvider.GetPromotions(p => p.ProductId == promotion.ProductId && p.Quantity == promotion.Quantity).Any()) { StringBuilder sb = new StringBuilder(); sb.Append("A product promotion exists with quantity "); sb.Append(promotion.Quantity.ToString()); throw new BusinessException(sb.ToString()); } else { return(mapper.getDTO(promotionDataAccessProvider.AddPromotion(mapper.getEntity(promotion)))); } }
public async Task <Result <PromotionDTO> > AddPromotionAsync(PromotionDTO feedback) { Promotion promotion = Mapper.Map <PromotionDTO, Promotion>(feedback); Promotion res = await _unitOfWork.EntityRepository <Promotion>().CreateAsync(promotion, (string)null); await _unitOfWork.SaveChangesAsync(); string name = _unitOfWork.EntityRepository <Place>().GetFirst((Expression <Func <Place, bool> >)((Place w) => w.Id == feedback.PlaceId), (Func <IQueryable <Place>, IOrderedQueryable <Place> >)null, Array.Empty <Expression <Func <Place, object> > >()).Name; string email = _unitOfWork.EntityRepository <User>().GetFirst((Expression <Func <User, bool> >)((User w) => w.Id == feedback.UserId), (Func <IQueryable <User>, IOrderedQueryable <User> >)null, Array.Empty <Expression <Func <User, object> > >()).Email; await _emailSender.Send((IEnumerable <string>) new string[1] { email }, "Hesabınıza promosyon tanımlandı!", name + " mekanından hesabınıza promosyon tanımlandı <br/> Promosyon: " + feedback.Message); return(Result.Data <PromotionDTO>(Mapper.Map <Promotion, PromotionDTO>(res))); }
public PromotionDTO UpdatePromotion(int id, PromotionDTO updatedPromotionDTO) { if (_uow.Promotions.Exists(id)) { Promotion promotion = _uow.Promotions.Find(id); promotion.Name = updatedPromotionDTO.Name; promotion.Description = updatedPromotionDTO.Description; promotion.Type = updatedPromotionDTO.Type; promotion.ValidTo = updatedPromotionDTO.ValidTo; promotion.ClassName = updatedPromotionDTO.ClassName; _uow.Promotions.Update(promotion); _uow.SaveChanges(); } return(GetPromotionById(id)); }
private decimal GetPrice(ProductDTO product, ref int productItemCount, ref bool promotionApplied, OrderDTO order) { // set the price (including a discount) decimal price = product.Price; if (product.Promotions.Count > 0) { // assume the service only return 1 active promotion PromotionDTO promotion = product.Promotions.First(); if (promotion.PromotionCode == Constants.PromotionType.Discount) { // we reset the productItemCount once the promotion reaches the max apply to count if (promotion.ApplyTo != null && productItemCount > promotion.Quantity + promotion.ApplyTo) { productItemCount = 1; } // set the price by the percentage discount if (productItemCount > promotion.Quantity) { price = price * promotion.Amount; promotionApplied = true; } } else if (promotion.PromotionCode == Constants.PromotionType.Price && productItemCount == promotion.Quantity) { // for a price by a number of items, we set the price on the final item in the group, and set // all other items in the group to a price of 0 for (int i = order.OrderItems.Count - 1; i >= order.OrderItems.Count - promotion.Quantity + 1; i--) { OrderItemDTO orderItemPriceAdjustment = order.OrderItems.ToList()[i]; orderItemPriceAdjustment.Price = 0; orderItemPriceAdjustment.PromotionApplied = true; } price = promotion.Amount; productItemCount = 0; promotionApplied = true; } } return(price); }
public IActionResult UpdatePromotion(int id, [FromBody] PromotionDTO promotionDTO) { _requestLogService.SaveRequest(User.Identity.GetUserId(), "PUT", "api/v1/promotions/{id}", "UpdatePromotion"); if (!ModelState.IsValid) { return(BadRequest()); } var p = _promotionService.GetPromotionById(id); if (p == null) { return(NotFound()); } PromotionDTO updatedPromotion = _promotionService.UpdatePromotion(id, promotionDTO); return(Ok(updatedPromotion)); }
//private static readonly string connectionString = ConfigurationManager.AppSettings["defaultConnectionString"].ToString(); //public GetCartDetails(int Cart) public List <PromotionDTO> GetActivePromotions() { List <PromotionDTO> promotionListObj = new List <PromotionDTO>(); PromotionDTO promotionObj; ShoppingCartDBEntities dbEntitiesObj = new ShoppingCartDBEntities(); var listObj = dbEntitiesObj.Promotions.ToList(); foreach (var item in listObj) { promotionObj = new PromotionDTO(); promotionObj.PromotionId = item.Promotion_Id; promotionObj.PromotionCode = item.Promotion_Code; promotionObj.CodeStatus = item.Code_Status; promotionListObj.Add(promotionObj); } return(promotionListObj); }
public IActionResult Promote(PromotionDTO promotionDTO) { if (!ModelState.IsValid) { var state = ModelState; return(BadRequest()); } Enrollment enrollment = _dbService.Promote(promotionDTO); if (enrollment != null) { return(Created("", enrollment)); } else { return(BadRequest()); } }
public void DisplayProducts() { List <ProductDTO> products = productService.GetProducts(); Console.WriteLine(); Console.WriteLine("Products:"); Console.WriteLine(); reportHandler.SetupColumns(30, 10, 30); reportHandler.AddColumns("Name", "Code", "Promotion"); reportHandler.AddColumns('-', "", "", ""); foreach (ProductDTO product in products) { string promotionDisplay = string.Empty; if (product.Promotions.Count > 0) { // we assume the service will only return one active promotion (promotions are stored in the DB) PromotionDTO promotion = product.Promotions.First(); if (promotion.PromotionCode == Constants.PromotionType.Discount) { promotionDisplay = String.Format("Buy {0}, Discount Next {1} to {2:P}", promotion.Quantity, promotion.ApplyTo, promotion.Amount); } else if (promotion.PromotionCode == Constants.PromotionType.Price) { promotionDisplay = String.Format("Buy {0} for {1:C}", promotion.Quantity, promotion.Amount); } } reportHandler.AddColumns(product.Description, product.Code, promotionDisplay); } reportHandler.GenerateReport(); }
/// <summary> /// Converts an Entity Framework list of promotions to a Promotion DTO /// </summary> /// <param name="promotions"></param> /// <returns>As Promotion DTO list</returns> private List <PromotionDTO> ConvertPromotionList(List <Promotion> promotions) { List <PromotionDTO> promotionsDTO = new List <PromotionDTO>(); foreach (Promotion promotion in promotions) { PromotionDTO promotionDTO = new PromotionDTO { Amount = promotion.Amount, ApplyTo = promotion.ApplyTo, EndDate = promotion.EndDate, Id = promotion.Id, PromotionCode = promotion.PromotionCode, ProductCode = promotion.PromotionCode, Quantity = promotion.Quantity, StartDate = promotion.StartDate }; promotionsDTO.Add(promotionDTO); } return(promotionsDTO); }
public static List <PromotionDTO> PreparePromotionCodeData() { PromotionDTO promotionObj; List <PromotionDTO> promotionList = new List <PromotionDTO>(); promotionObj = new PromotionDTO(); promotionObj.PromotionId = 1; promotionObj.PromotionCode = "3 of A's for 130"; promotionObj.CodeStatus = true; promotionList.Add(promotionObj); promotionObj = new PromotionDTO(); promotionObj.PromotionId = 2; promotionObj.PromotionCode = "2 of B's for 45"; promotionObj.CodeStatus = true; promotionList.Add(promotionObj); promotionObj = new PromotionDTO(); promotionObj.PromotionId = 3; promotionObj.PromotionCode = "C & D for 30"; promotionObj.CodeStatus = true; promotionList.Add(promotionObj); return(promotionList); }
public bool promo(PromotionDTO promo) { initTable(); using (var con = new SqlConnection( "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\cw3-master\\Cw3\\Cw3\\localDB.mdf;Integrated Security=True;Connect Timeout=30" // "Data Source=db-mssql;Initial Catalog=s16701;Integrated Security=True" )) using (var com = new SqlCommand()) { con.Open(); com.Connection = con; com.CommandText = $"SELECT * FROM dbo.Enrollment e JOIN dbo.Studies s on e.IdStudy = s.IdStudy WHERE e.Semester = {promo.Semester} and s.name = {promo.Studies}"; var dr = com.ExecuteReader(); if (dr.HasRows) // Student istnieje { initSP(); // utworzenie procedury com.CommandText = "exec dbo.promo"; com.ExecuteNonQuery(); return(true); } } return(false); }
public async Task <IActionResult> RemovePromotion([FromBody] PromotionDTO model) { var email = (await _userManager.GetUserAsync(HttpContext.User)).Email; var user = await _userRepository.FindByEmail(email); var business = user.Business; if (business == null) { return(Unauthorized()); } if (business.Promotions != null) { await _promotionRepository.RemovePromotion(new Promotion { Id = model.Id, Description = model.Description, Name = model.Name, PromotionType = model.PromotionType, StartDate = model.StartDate, EndDate = model.EndDate }); } return(Ok()); }
public PromotionDTO CreateComplex(Promotion promotion) { return(PromotionDTO.CreateFromDomainWithAssociatedTables(promotion)); }
public void Put(int id, [FromBody] PromotionDTO product) { promotionService.updatePromotion(product); }
public JsonResult Post([FromBody] PromotionDTO product) { return(Json(promotionService.addPromotion(product))); }
public void updatePromotion(PromotionDTO promotion) { promotionDataAccessProvider.UpdatePromotion(mapper.getEntity(promotion)); }