public GalleryViewModel Insert(GalleryViewModel objEntity) { try { Database objDB = base.GetDatabase(); // Create a suitable command type and add the required parameter. using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SP_GalleryViewModelInsert)) { objDB.AddInParameter(sprocCmd, PARAM_FileName, DbType.String, objEntity.FileName); objDB.AddInParameter(sprocCmd, PARAM_Title, DbType.String, objEntity.Title); objDB.AddOutParameter(sprocCmd, PARAM_Id, DbType.Int16, objEntity.Id); objDB.AddOutParameter(sprocCmd, PARAM_Result, DbType.Int32, objEntity.Result); objDB.ExecuteNonQuery(sprocCmd); objEntity.Id = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, PARAM_Id)); objEntity.Result = Convert.ToInt32(objDB.GetParameterValue(sprocCmd, PARAM_Result)); } } catch (Exception ex) { throw ex; } finally { } return objEntity; }
public ActionResult Create(GalleryViewModel objEntity) { GalleryViewModel objFileUpRepository = new GalleryViewModel(); GalleryRepository objfileRepository = new GalleryRepository(); string fileName = string.Empty; if (ModelState.IsValid) { if (!string.IsNullOrEmpty(objEntity.UpFile.FileName)) { fileName = Guid.NewGuid().ToString() + Path.GetExtension(objEntity.UpFile.FileName); objEntity.FileName = fileName; } objfileRepository.Insert(objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { //save image http://www.w3schools.com/aspnet/webpages_ref_helpers.asp //file name if (!string.IsNullOrEmpty(objEntity.UpFile.FileName)) { string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_EMPLOYER_GALLERY_PATH), fileName); // WebImage.Save() objEntity.UpFile.SaveAs(path); } this.Flash("success", "Image Addd successfully "); return RedirectToAction("Index"); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("error", "Faild to Insert File"); return RedirectToAction("Index"); } else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode()) { this.Flash("warning", "File is Already Exist"); return RedirectToAction("Index"); } } return View(objEntity); }
public ActionResult Details(int id) { var objStudentRepository = new GalleryRepository(); var objEntity = new GalleryViewModel(); objEntity = objStudentRepository.Select(GalleryFlags.SelectByID.GetHashCode(), new GalleryViewModel() { Id = id }).FirstOrDefault(); if (objEntity == null) { return RedirectToAction("Index"); } return View(objEntity); }
public List<GalleryViewModel> Search(int flag, GalleryViewModel entity) { var objEntityList = new List<GalleryViewModel>(); try { Database objDB = base.GetDatabase(); // Create a suitable command type and add the required parameter. using (DbCommand sprocCmd = objDB.GetStoredProcCommand(SP_GalleryViewModelSelect)) { objDB.AddInParameter(sprocCmd, PARAM_Flag, DbType.Int32, flag); objDB.AddInParameter(sprocCmd, PARAM_Id, DbType.Int32, entity.Id); using (IDataReader reader = objDB.ExecuteReader(sprocCmd)) { while (reader.Read()) { var objEntityViewModel = new GalleryViewModel(); objEntityViewModel.Id = reader.GetColumnValue<int>(PARAM_GalleryId); objEntityViewModel.FileName = (reader.GetColumnValue<string>(PARAM_FileName)); objEntityViewModel.Title = reader.GetColumnValue<string>(PARAM_Title); if (objEntityViewModel != null) { objEntityList.Add(objEntityViewModel); } } } } } catch (Exception ex) { throw ex; } finally { } return objEntityList; }
public ActionResult Edit(int id, GalleryViewModel objEntity) { var objStudentRepository = new GalleryRepository(); string fileName = string.Empty; objEntity.Id = id; objEntity.DeleteFileName = objEntity.FileName; if (!string.IsNullOrEmpty(objEntity.UpFile.FileName)) { fileName = Guid.NewGuid().ToString() + Path.GetExtension(objEntity.UpFile.FileName); objEntity.FileName = fileName; } objEntity = objStudentRepository.Edit(GalleryFlags.UpdateByID.GetHashCode(), objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { if ((objEntity.DeleteFileName != null || objEntity.DeleteFileName != string.Empty) && !string.IsNullOrEmpty(objEntity.UpFile.FileName)) { FileInfo file = new FileInfo(Server.MapPath(ApplicationConstant.UPLOADED_EMPLOYER_GALLERY_PATH + objEntity.DeleteFileName)); if (file.Exists) { file.Delete(); } string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_EMPLOYER_GALLERY_PATH), fileName); // WebImage.Save() objEntity.UpFile.SaveAs(path); } this.Flash("success", "Student Details updated successfully"); return RedirectToAction("Index"); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("error", "Student Details failed to Update"); } else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode()) { this.Flash("warning", "Student Name is Already Exist"); } return View(objEntity); }