//Update a record public static int UpdateRecord(eTblPromotionalHotel eobj) { int retval = -1; using (OneFineRateEntities db = new OneFineRateEntities()) { try { var existingModel = db.tblPromotionalHotelsMs.FirstOrDefault(x => x.sPosition == eobj.sPosition); if (existingModel != null) { existingModel.iPropId = eobj.iPropId; existingModel.sDescription = eobj.sDescription; existingModel.sImageUrl = eobj.sImageUrl; existingModel.iActionBy = eobj.iActionBy; existingModel.dtActionDate = eobj.dtActionDate; existingModel.sPosition = eobj.sPosition; } //db.Entry(existingModel).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); retval = 1; } catch (Exception) { throw; } } return(retval); }
public ActionResult Index(eTblPromotionalHotel model, HttpPostedFileBase file) { if (ModelState.IsValid) { int status = -1; if (file != null) { if (IsValideImage(file)) { using (MemoryStream target = new MemoryStream()) { file.InputStream.CopyTo(target); byte[] data = target.ToArray(); var uniqueFileName = model.sPosition + Path.GetExtension(file.FileName); var currentUploadedFileUrl = clsUtils.Upload_Promotional_Hotel_Image_To_BlobStorage("promotionalhotels", uniqueFileName, data, 165, 245); model.iActionBy = ((OneFineRateBLL.BL_Login.UserDetails)Session["UserDetails"]).iUserId; model.dtActionDate = DateTime.Now; model.sImageUrl = "promotionalhotels/" + uniqueFileName; status = BL_tblPromotionalHotel.UpdateRecord(model); } } else { TempData["ERROR"] = "Invalid Images ! Please upload only .jpg, .png, .jpeg or .bmp images"; } } else if (!string.IsNullOrEmpty(model.sImageUrl)) { model.iActionBy = ((OneFineRateBLL.BL_Login.UserDetails)Session["UserDetails"]).iUserId; model.dtActionDate = DateTime.Now; status = BL_tblPromotionalHotel.UpdateRecord(model); } else { TempData["ERROR"] = "Please select an Image to upload!"; return(RedirectToAction("Index")); } if (status == 1) { TempData["msg"] = "Promotinal Image mapping updated successfully !"; } else if (status == 0) { TempData["ERROR"] = "An unkown error had happen ! Images not updated ."; } } return(RedirectToAction("Index")); }
//Get Single Record public static eTblPromotionalHotel GetSingleRecordById(string sPosition) { eTblPromotionalHotel eobj = new eTblPromotionalHotel(); using (OneFineRateEntities db = new OneFineRateEntities()) { var dbobj = db.tblPromotionalHotelsMs.SingleOrDefault(u => u.sPosition == sPosition); if (dbobj != null) { eobj = (eTblPromotionalHotel)OneFineRateAppUtil.clsUtils.ConvertToObject(dbobj, new eTblPromotionalHotel()); } } return(eobj); }
//Add new record public static int AddUpdateRecord(eTblPromotionalHotel eobj) { int retval = 0; using (OneFineRateEntities db = new OneFineRateEntities()) { try { OneFineRate.tblPromotionalHotelsM dbstate = (OneFineRate.tblPromotionalHotelsM)OneFineRateAppUtil.clsUtils.ConvertToObject(eobj, new OneFineRate.tblPromotionalHotelsM()); db.tblPromotionalHotelsMs.Add(dbstate); db.SaveChanges(); retval = 1; } catch (Exception) { throw; } } return(retval); }