public ActionResult AddOrEdit(BKRY_ITEMS bkt, HttpPostedFileBase file) { byte[] buf = null; if (file != null && file.ContentLength > 0) { buf = new byte[file.ContentLength]; file.InputStream.Read(buf, 0, buf.Length); bkt.image = buf; } bkt.insert_by = Session != null && Session["UserName"] != null ? Session["UserName"].ToString() : ""; bkt.add_date = DateTime.Now; bkt.categoryId = Convert.ToInt64(Request.Form["categoryname"] != "" ? Request.Form["categoryname"] : "0"); using (BKRY_MNGT_SYSEntities db = new BKRY_MNGT_SYSEntities()) { if (bkt.Id == 0) { db.BKRY_ITEMS.Add(bkt); db.SaveChanges(); return(RedirectToAction("Index")); } else { db.Entry(bkt).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbEntityValidationException e) { throw e; } return(RedirectToAction("Index")); } } }
public ActionResult AddOrEdit(BKRY_CATEGORY bkt, HttpPostedFileBase file) { try { byte[] buf = null; if (file != null && file.ContentLength > 0) { buf = new byte[file.ContentLength]; file.InputStream.Read(buf, 0, buf.Length); bkt.image = buf; } bkt.insert_by = Session != null && Session["UserName"] != null ? Session["UserName"].ToString() : ""; bkt.add_date = DateTime.Now; using (BKRY_MNGT_SYSEntities db = new BKRY_MNGT_SYSEntities()) { if (bkt.Id == 0) { db.BKRY_CATEGORY.Add(bkt); db.SaveChanges(); return(RedirectToAction("Index")); } else { db.Entry(bkt).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(null); }
public ActionResult CreateUser(SYS_USR_INFO objOn) { string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(ipAddress)) { ipAddress = Request.ServerVariables["REMOTE_ADDR"]; } Dictionary <string, string> osList = new Dictionary <string, string> { { "Windows NT 6.3", "Windows 8.1" }, { "Windows NT 6.2", "Windows 8" }, { "Windows NT 6.1", "Windows 7" }, { "Windows NT 6.0", "Windows Vista" }, { "Windows NT 5.2", "Windows Server 2003" }, { "Windows NT 5.1", "Windows XP" }, { "Windows NT 5.0", "Windows 2000" } }; string userAgentText = Request.UserAgent; string osVersion = ""; if (userAgentText != null) { int startPoint = userAgentText.IndexOf('(') + 1; int endPoint = userAgentText.IndexOf(';'); osVersion = userAgentText.Substring(startPoint, (endPoint - startPoint)); //string friendlyOsName = osList[osVersion]; } SYS_USR_INFO userinfo = new SYS_USR_INFO(); try { using (BKRY_MNGT_SYSEntities db = new BKRY_MNGT_SYSEntities()) { SYS_USR_INFO obj = new SYS_USR_INFO { UserId = (objOn.UserId > 0) ? objOn.UserId : 0, UserName = objOn.UserName, UserPassowrd = objOn.UserPassowrd, MachineIP = ipAddress, OperatingSystem = osVersion, LoginTime = DateTime.Now, LoginErrorMessage = JsonConvert.SerializeObject(userinfo), address = objOn.address, email = objOn.email, street = objOn.street, phone = objOn.phone, postCode = objOn.postCode }; if (db.SYS_USR_INFO.Where(x => x.UserName == obj.UserName).ToList().Count == 0) { db.SYS_USR_INFO.Add(obj); db.Entry(obj).State = EntityState.Added; db.SaveChanges(); Session["Message"] = "Saved Successfully your UserName# is " + obj.UserName.ToString(); } else { db.SYS_USR_INFO.Remove(db.SYS_USR_INFO.Where(x => x.UserName == obj.UserName).ToList().FirstOrDefault()); db.SYS_USR_INFO.Add(obj); db.SaveChanges(); Session["Message"] = "Updated Successfully your UserName# is " + obj.UserName.ToString(); } return(RedirectToAction("LogOut", "Login")); } } catch (Exception ex) { return(Json(new { success = true, message = "UnSuccessfully" + ex.ToString() }, JsonRequestBehavior.AllowGet)); } }