public static void Create(PrizeDTO prizeDTO) { Prize prize = MapperTransform <Prize, PrizeDTO> .ToEntity(prizeDTO); Database.Prizes.Create(prize); Database.Save(); }
public static void Update(PrizeDTO prizeDTO) { Prize prize = Database.Prizes.Get(prizeDTO.Id); prize.Name = prizeDTO.Name; prize.QuestId = prizeDTO.QuestId; prize.MaxPlace = prizeDTO.MaxPlace; prize.MinPlace = prizeDTO.MinPlace; Database.Prizes.Update(prize); Database.Save(); }
public bool Edit(PrizeDTO PRP) { try { P_DAL.Edit(PRP); } catch (Exception ex) { return(false); } return(true); }
public bool UpdatePrize(PrizeDTO prize) { try { this.competitionUnitOfWork.PrizeRepository.Update(ObjectMapper <PrizeDTO, PrizeEntity> .Map(prize)); this.competitionUnitOfWork.SaveChanges(); } catch (Exception) { return(false); } return(true); }
public async Task <ActionResult> UpdatePrize([FromBody] PrizeDTO prize) { if (ModelState.IsValid) { bool result = await _prizeService.UpdatePrizeAsync(prize); if (result) { return(Ok("The update was successful.")); } } return(BadRequest("Something went wrong try again.")); }
protected void function_insert_Click(object sender, EventArgs e) { PrizeDTO PRP = new PrizeDTO(); PRP.NAME_PRIZE = input_Name_prize.Text; PRP.REWARD = float.Parse(input_Reward.Text); if (PBL.Insert(PRP) == true) { MessageBox("Thêm thành công", "Prize.aspx"); uploadData(); } else { MessageBox("Thêm không thành công", "Prize.aspx"); uploadData(); } }
public async Task <bool> CreatePrizeAsync(PrizeDTO prize) { bool check = await PrizeWithSameNumOfHitsAsync(prize.NumberOfHits); if (!check) { Prize newPrize = _mapper.Map <Prize>(prize); int result = await Task.Run(() => _prizeRepository.Add(newPrize)); if (result != -1) { return(true); } } return(false); }
protected void btn_edit_Click(object sender, EventArgs e) { PrizeDTO TLO = new PrizeDTO(); TLO.NAME_PRIZE = input_Name_prize.Text; TLO.REWARD = float.Parse(input_Reward.Text); TLO.ID_PRIZE = input_Id_prize.Text; if (TBL.Edit(TLO) == true) { MessageBox("Sửa thành công", "Type_Lottery.aspx"); } else { MessageBox("Sửa không thành công", "Type_Lottery.aspx"); } }
public async Task <bool> UpdatePrizeAsync(PrizeDTO prize) { Prize match = await Task.Run(() => _prizeRepository.GetById(prize.PrizeId)); if (match != null) { match.Name = !String.IsNullOrEmpty(prize.Name) ? prize.Name : match.Name; match.NumberOfHits = prize.NumberOfHits > 0 ? prize.NumberOfHits : match.NumberOfHits; int result = await Task.Run(() => _prizeRepository.Update(match)); if (result != -1) { return(true); } } return(false); }
public void Insert(PrizeDTO PRP) { ConnectDB.con.Open(); try { SqlCommand cmd = new SqlCommand("insert_PRIZE", ConnectDB.con); cmd.Parameters.Add("@NAME_PRIZE", SqlDbType.NVarChar).Value = PRP.NAME_PRIZE; cmd.Parameters.Add("@REWARD", SqlDbType.Float).Value = PRP.REWARD; cmd.CommandType = CommandType.StoredProcedure; cmd.ExecuteNonQuery(); } catch { throw; } finally { ConnectDB.con.Close(); } }
public void AddOrUpdatePrize(PrizeModel prize) { var check = _prizeRepository.GetAll().FirstOrDefault(p => p.NumberOfHits == prize.NumberOfHits); PrizeDTO newPrize = new PrizeDTO() { NumberOfHits = prize.NumberOfHits, Prize = prize.Prize }; if (check == null) { _prizeRepository.Add(newPrize); } else { _prizeRepository.Delete(check); _prizeRepository.Update(newPrize); } }
public ActionResult AddQuest(UpdateQuest quest) { DateTime DateCreate = DateTime.Now; if (quest.Points.Count > 2 && quest.Name != null && quest.Prizes.Count > 0 && Identity.isAuthentication || true) { if (quest.Id != null) { int ID = quest.Id.Value; QuestDTO questDTO = QuestServices.Get(ID); questDTO.StartQuest = quest.DateTime; questDTO.Description = quest.Description; questDTO.LimitOfPeople = Convert.ToInt32(quest.MaxPeople); questDTO.Name = quest.Name; QuestServices.Update(questDTO); if (quest.Photo != null) { string dir = Server.MapPath("~/Resources/Images/Quest"); string type = quest.Photo.FileName.Split('.').Last(); string src = "/Resources/Images/Quest/" + cryptMD5.GetHash(Convert.ToString(questDTO.Id)) + "." + type; string path = Server.MapPath("~" + src); quest.Photo.SaveAs(path); questDTO.SRC = src; QuestServices.Update(questDTO); } List <PrizeDTO> prizeDTO = PrizeServices.GetAll().Where(x => x.QuestId == ID).ToList(); List <PointDTO> pointDTO = PointServices.GetAll().Where(x => x.QuestId == ID).ToList(); foreach (PrizeDTO prz in prizeDTO) { PrizeServices.Delete(prz.Id); } foreach (PointDTO pnt in pointDTO) { PointServices.Delete(pnt.Id); } PrizeDTO prizeDTOnew; PointDTO pointDTOnew; foreach (UpdateQuest.Prize prize in quest.Prizes) { prizeDTOnew = new PrizeDTO(); prizeDTOnew.MaxPlace = prize.Max; prizeDTOnew.MinPlace = prize.Min; prizeDTOnew.Name = prize.Title; prizeDTOnew.QuestId = ID; PrizeServices.Create(prizeDTOnew); } foreach (UpdateQuest.Point point in quest.Points) { pointDTOnew = new PointDTO(); pointDTOnew.Latitude = point.getLatitude(); pointDTOnew.Longitude = point.getLongitude(); pointDTOnew.Task = point.Task; pointDTOnew.QuestId = ID; pointDTOnew.Address = point.Address; PointServices.Create(pointDTOnew); } TempData["Message"] = "Успешно отредактировано"; return(Redirect("/Home/Home")); } else { QuestDTO questDTO = new QuestDTO(); questDTO.StartQuest = quest.DateTime; questDTO.DateCreate = DateCreate; questDTO.Description = quest.Description; questDTO.LimitOfPeople = Convert.ToInt32(quest.MaxPeople); questDTO.Name = quest.Name; questDTO.Creater = Identity.user.Id; QuestServices.Create(questDTO); QuestDTO newQuestDTO = QuestServices.GetAll().FirstOrDefault(x => x.Name == quest.Name && x.Creater == Identity.user.Id && x.DateCreate == DateCreate); if (quest.Photo != null) { string dir = Server.MapPath("~/Resources/Images/Quest"); string type = quest.Photo.FileName.Split('.').Last(); string src = "/Resources/Images/Quest/" + cryptMD5.GetHash(Convert.ToString(newQuestDTO.Id)) + "." + type; string path = Server.MapPath("~" + src); quest.Photo.SaveAs(path); newQuestDTO.SRC = src; QuestServices.Update(newQuestDTO); } PrizeDTO prizeDTO; PointDTO pointDTO; foreach (UpdateQuest.Prize prize in quest.Prizes) { prizeDTO = new PrizeDTO(); prizeDTO.MaxPlace = prize.Max; prizeDTO.MinPlace = prize.Min; prizeDTO.Name = prize.Title; prizeDTO.QuestId = newQuestDTO.Id; PrizeServices.Create(prizeDTO); } foreach (UpdateQuest.Point point in quest.Points) { pointDTO = new PointDTO(); pointDTO.Latitude = point.getLatitude(); pointDTO.Longitude = point.getLongitude(); pointDTO.Task = point.Task; pointDTO.QuestId = newQuestDTO.Id; pointDTO.Address = point.Address; PointServices.Create(pointDTO); } TempData["Message"] = "Успешно добавлено"; return(Redirect("/Home/Home")); } } TempData["Message"] = "Квест не добавлен"; return(RedirectToAction("Quest")); }