public EventsandTip UpdateEventandTip(EventsandTip eventAndTip, long id) { DateTime updateddate = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE); eventAndTip.UpdatedDate = updateddate; eventAndTip.Status = "Active"; eventsandTipRepository.UpdateEventsAndTip(eventAndTip, id); return(eventAndTip); }
public EventsandTip UpdateEventsAndTip(EventsandTip eventAndTip, long id) { var GetRecord = _dbContext.EventsandTip.Where(m => m.EventId == id).FirstOrDefault(); eventAndTip.EventId = GetRecord.EventId; eventAndTip.UpdatedBy = GetRecord.UpdatedBy; //eventAndTip.Image = GetRecord.Image; _dbContext.Entry(GetRecord).CurrentValues.SetValues(eventAndTip); _dbContext.SaveChanges(); return(eventAndTip); }
public ActionResult Index(EventsandTip eventAndTip,HttpPostedFileBase file,string Command,string id) { var user = (CustomPrincipal)System.Web.HttpContext.Current.User; EventsandtipsService eventsAndTipsService = new EventsandtipsService(); long value = eventsAndTipsService.EventIDCount(); string fileName = string.Empty; string ImagesURL = string.Empty; eventAndTip.UpdatedBy = user.UserId; if (Command == "Save") { if (Request.Files.Count <= 10) { for (int i = 0; i < Request.Files.Count; i++) { int j = i + 1; var file1 = Request.Files[i]; if (file1 != null && file1.ContentLength > 0) { var filename = string.Empty; string path = System.IO.Path.GetExtension(file.FileName); if (eventAndTip.Type == "Event") { filename = eventAndTip.Type + "_" + value + "_" + j + path; } else if (eventAndTip.Type == "Beauty Tips") { filename = "Beauty_" + value + "_" + j + path; } else if (eventAndTip.Type == "Health Tips") { filename = "Health_" + value + "_" + j + path; } fileName = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath(imagepath + filename)); file1.SaveAs(fileName); ImagesURL += filename + ","; } } } eventAndTip.Image = ImagesURL.TrimEnd(','); eventAndTip = eventsAndTipsService.AddEventandTip(eventAndTip); if (eventAndTip.EventId != 0) return Content("<script language='javascript' type='text/javascript'>alert('Registered Successfully');location.href='" + @Url.Action("Index", "EventsTips") + "'</script>"); return Content("<script language='javascript' type='text/javascript'>alert('Registration Failed!!!');location.href='" + @Url.Action("Index", "EventsTips") + "'</script>"); } if (Command == "Update") { var particularevent = eventsandtipsService.GetEventandTip(long.Parse(id)); string x = particularevent.Image.ToString(); ViewBag.images = x.Split(','); int count = Enumerable.Count(ViewBag.images); ViewBag.imagescount = count; int imageno = 0; string x1 = ViewBag.images[0].ToString(); string[] y = x1.Split('_', '.'); if (y[0]!= "" && y != null) { imageno = int.Parse(y[1]); } if (Request.Files.Count <= 10 - count) { for (int i = 0; i < Request.Files.Count; i++) { int j = count + 1+i; var file1 = Request.Files[i]; if (file1 != null && file1.ContentLength > 0) { var filename = string.Empty; string path = System.IO.Path.GetExtension(file.FileName); if (eventAndTip.Type == "Event") { filename = eventAndTip.Type + "_" + imageno + "_" + j + path; } else if (eventAndTip.Type == "Beauty Tips") { filename = "Beauty_" + imageno + "_" + j + path; } else if (eventAndTip.Type == "Health Tips") { filename = "Health_" + imageno + "_" + j + path; } fileName = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath(imagepath + filename)); file1.SaveAs(fileName); ImagesURL += filename + ","; } } eventAndTip.Image = particularevent.Image + "," + ImagesURL.TrimEnd(','); eventAndTip = eventsAndTipsService.UpdateEventandTip(eventAndTip, long.Parse(id)); if (eventAndTip.EventId != 0) return Content("<script language='javascript' type='text/javascript'>alert('Updated Successfully');location.href='" + @Url.Action("AllRecords", "EventsTips") + "'</script>"); return Content("<script language='javascript' type='text/javascript'>alert('Update Failed!!!');location.href='" + @Url.Action("AllRecords", "EventsTips") + "'</script>"); } else { if (file != null) { return Content("<script language='javascript' type='text/javascript'>alert('You have Crossed Images Limit');location.href='" + @Url.Action("Index", "EventsTips", new { id = id }) + "'</script>"); } else { eventAndTip.Image = particularevent.Image; eventAndTip = eventsAndTipsService.UpdateEventandTip(eventAndTip, long.Parse(id)); if (eventAndTip.EventId != 0) return Content("<script language='javascript' type='text/javascript'>alert('Updated Successfully');location.href='" + @Url.Action("AllRecords", "EventsTips") + "'</script>"); return Content("<script language='javascript' type='text/javascript'>alert('Update Failed!!!');location.href='" + @Url.Action("AllRecords", "EventsTips") + "'</script>"); } } } return View(); }
public EventsandTip AddEventsAndTip(EventsandTip eventAndTip) { _dbContext.EventsandTip.Add(eventAndTip); _dbContext.SaveChanges(); return(eventAndTip); }