public ActionResult Create([Bind(Include = "GroupName,ID,Description")] SupplierGroupModels supplierGroupModels) { if (ModelState.IsValid) { try { db.SupplierGroupModels.Add(supplierGroupModels); db.SaveChanges(); } catch (DbUpdateException ex) { var sqlException = ex.InnerException.InnerException as SqlException; if (sqlException != null && sqlException.Number == 2627) { //Response.Write("LeterNo already registered!"); ViewBag.error = "Group already registered!"; ModelState.AddModelError("", "Group already registered!"); return(View(supplierGroupModels)); } } return(RedirectToAction("Index")); } ModelState.AddModelError("", "Data Error!"); return(View(supplierGroupModels)); }
public ActionResult Create([Bind(Include = "ID,Name,Password")] Admin admin) { if (ModelState.IsValid) { db.Admins.Add(admin); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Create", "_AdminLayout", admin)); }
public ActionResult Create([Bind(Include = "Id,Name")] MasterCity masterCity) { if (ModelState.IsValid) { db.MasterCities.Add(masterCity); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(masterCity)); }
public ActionResult PartialCreate([Bind(Include = "ID,CompanyName,OwnerName,Address")] CompanyNameModels companyNameModels) { if (ModelState.IsValid) { db.CompanyNameModels.Add(companyNameModels); db.SaveChanges(); return(View("Create", "SupplierModels", db.SupplierModels));//RedirectToAction("Index"); } return(View(companyNameModels)); }
public ActionResult Create([Bind(Include = "Id,Name")] ItemMaster itemMaster) { if (ModelState.IsValid) { db.ItemMasters.Add(itemMaster); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(itemMaster)); }
public ActionResult Create([Bind(Include = "ID,WelcomeNotice")] welcomeNoticeModels welcomeNoticeModels) { if (ModelState.IsValid) { db.welcomeNoticeModels.Add(welcomeNoticeModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(welcomeNoticeModels)); }
public ActionResult Create([Bind(Include = "ID,Name,duty,AddressLine1,AddressLine2,AddressLine3,AddressLine4,cell,phone,fax,email")] ContactModels contactModels) { if (ModelState.IsValid) { db.ContactModels.Add(contactModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contactModels)); }
public ActionResult Create([Bind(Include = "Id,Name,SortOrder")] ItemCatGroup itemCatGroup) { if (ModelState.IsValid) { db.ItemCatGroups.Add(itemCatGroup); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(itemCatGroup)); }
public ActionResult Create([Bind(Include = "ID,TenderNo,DescriptionOfItem,TotalPages,TotalAmount,IDCardNo,Name,NameOfTheFirm,Address")] CashPPCModels cashPPCModels) { if (ModelState.IsValid) { cashPPCModels.PPCDate = DateTime.Now; db.CashPPCModels.Add(cashPPCModels); db.SaveChanges(); return(RedirectToAction("Index"));//"PPCCopySalesReport"); } return(View(cashPPCModels)); }
public ActionResult Create([Bind(Include = "ID,loginName,Nume,Prenume,Parola,Logged")] Admin admin) { if (ModelState.IsValid) { admin.Parola = getMd5Hash(admin.Parola); db.Users.Add(admin); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(admin)); }
public ActionResult Create([Bind(Include = "ID,PurchaseOrderNo,LDReferenceNo,PODate,CompanyName,LDAmount,TotalAmount,Percent")] LDModels lDModels) { ViewBag.PurchaseOrderNolist = new SelectList(db.ProcurementAndTenderModels.Where(x => x.PurchaseOrderNo != null).ToList(), "PurchaseOrderNo", "PurchaseOrderNo"); if (ModelState.IsValid) { db.LDModels.Add(lDModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lDModels)); }
public ActionResult Create([Bind(Include = "Id,Name,MasterCityId")] MasterArea masterArea) { if (ModelState.IsValid) { db.MasterAreas.Add(masterArea); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MasterCityId = new SelectList(db.MasterCities, "Id", "Name", masterArea.MasterCityId); return(View(masterArea)); }
public ActionResult Create([Bind(Include = "Id,Name,SortOrder,ItemCatGroupId")] ItemCategory itemCategory) { if (ModelState.IsValid) { db.ItemCategories.Add(itemCategory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ItemCatGroupId = new SelectList(db.ItemCatGroups, "Id", "Name", itemCategory.ItemCatGroupId); return(View(itemCategory)); }
public ActionResult Create([Bind(Include = "Id,UserId,Name,Address,Mobile,Remarks,RiderStatusId,MasterCityId,Mobile2")] RiderDetail riderDetail) { if (ModelState.IsValid) { db.RiderDetails.Add(riderDetail); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MasterCityId = new SelectList(db.MasterCities, "Id", "Name", riderDetail.MasterCityId); ViewBag.RiderStatusId = new SelectList(db.RiderStatus, "Id", "Name", riderDetail.RiderStatusId); return(View(riderDetail)); }
public ActionResult Create([Bind(Include = "ID,DescriptionOfNotice,NoticeDownloadUrl")] GeneralNoticeModels generalNoticeModels, HttpPostedFileBase file1) { string subPath = "~/GeneralNotice"; // your code goes here bool exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } subPath = "~/GeneralNotice"; if (file1 == null) { ModelState.AddModelError("", "File is not attached!"); } HttpPostedFileBase file = file1; if (ModelState.IsValid) { //////////////// if (file != null) { var allowedExtensions = new[] { ".pdf" }; var fileName = Path.GetFileName(file.FileName); var ext = Path.GetExtension(file.FileName); //getting the extension(ex-.jpg) if (allowedExtensions.Contains(ext)) //check what type of extension { string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension string myfile = name + ext; //appending the name with id // store the file inside ~/project folder(Img) var path = Path.Combine(Server.MapPath("~/GeneralNotice"), myfile); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } generalNoticeModels.NoticeDownloadUrl = Path.Combine("~/GeneralNotice", myfile); file.SaveAs(path); } } /////////////// db.GeneralNoticeModels.Add(generalNoticeModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(generalNoticeModels)); }
public ActionResult Create([Bind(Include = "Id,StoreDetailId,dtPayment,Amount,StorePaymentTypeId,Remarks,dtPosted,StorePaymentStatusId")] StorePayment storePayment) { if (ModelState.IsValid) { db.StorePayments.Add(storePayment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StoreDetailId = new SelectList(db.StoreDetails, "Id", "Name", storePayment.StoreDetailId); ViewBag.StorePaymentStatusId = new SelectList(db.StorePaymentStatus, "Id", "Name", storePayment.StorePaymentStatusId); ViewBag.StorePaymentTypeId = new SelectList(db.StorePaymentTypes, "Id", "Description", storePayment.StorePaymentTypeId); return(View(storePayment)); }
public bool BlockUnblockUser(string userId) { try { var appUser = context.CustomUsers.Where(u => u.Id == userId).FirstOrDefault(); appUser.IsBlocked = !appUser.IsBlocked; context.SaveChanges(); return(true); } catch (Exception) { throw; } }
public ActionResult Create(ProcurementAndTenderModels procurementAndTenderModels, HttpPostedFileBase fileITReference) { ViewBag.error = ""; allViewbags(); if (ModelState.IsValid) { try { db.ProcurementAndTenderModels.Add(procurementAndTenderModels); db.SaveChanges(); } catch (SqlException e) { if (e.ErrorCode == 2601) { Response.Write("Student already registered!"); return(View(procurementAndTenderModels)); } } catch (DbUpdateException ex) { var sqlException = ex.InnerException.InnerException as SqlException; if (sqlException != null && sqlException.Number == 2627) { //Response.Write("LeterNo already registered!"); ViewBag.error = "Record already registered!"; return(View(procurementAndTenderModels)); } } string subPath = "~/ProcurementAndTender/" + "ITRef" + "/" + procurementAndTenderModels.ID.ToString(); bool exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } check_file(fileITReference, procurementAndTenderModels, "ITRef", procurementAndTenderModels.ID); db.Set <ProcurementAndTenderModels>().AddOrUpdate(procurementAndTenderModels); //db.Entry(procurementAndTenderModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(procurementAndTenderModels)); }
public ActionResult Create([Bind(Include = "Id,LoginId,Name,Address,Remarks,StoreStatusId,StoreCategoryId,MasterCityId,MasterAreaId")] StoreDetail storeDetail) { if (ModelState.IsValid) { db.StoreDetails.Add(storeDetail); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MasterAreaId = new SelectList(db.MasterAreas, "Id", "Name", storeDetail.MasterAreaId); ViewBag.MasterCityId = new SelectList(db.MasterCities, "Id", "Name", storeDetail.MasterCityId); ViewBag.StoreCategoryId = new SelectList(db.StoreCategories, "Id", "Name", storeDetail.StoreCategoryId); ViewBag.StoreStatusId = new SelectList(db.StoreStatus, "Id", "Name", storeDetail.StoreStatusId); return(View(storeDetail)); }
public ValuesController(AdminDBContext context) { _context = context; if (_context.Customers.Count() == 0) { _context.Customers.Add(new Customer { CustomerName = "Axtest" }); _context.SaveChanges(); } }
public IActionResult Post([FromBody] Customer value) { if (value == null) { return(BadRequest()); } _context.Customers.Add(value); _context.SaveChanges(); return(StatusCode(200)); }
/* * Create By 蒋予飞 * 通过ID删除管理员 */ public int deleteAdminById(string id) { try { AdminDBContext adminDB = new AdminDBContext(); Admin admin = adminDB.admins.Find(id); adminDB.admins.Remove(admin); return(adminDB.SaveChanges()); } catch (Exception e) { return(-1); } }
/* * Create By 蒋予飞 * 按管理员ID更新姓名 */ public int changeNameById(string id, string name) { try { AdminDBContext adminDB = new AdminDBContext(); Admin admin = adminDB.admins.Find(id); admin.name = name; return(adminDB.SaveChanges()); } catch (Exception e) { return(-1); } }
/* * Create By 蒋予飞 * 按管理员ID更新密码 */ public int changePasswdById(string id, string password) { try { AdminDBContext adminDB = new AdminDBContext(); Admin admin = adminDB.admins.Find(id); admin.password = password; return(adminDB.SaveChanges()); } catch (Exception e) { return(-1); } }
/* * Create By 蒋予飞 * 添加管理员 */ public int addAdmin(Admin admin) { try { AdminDBContext adminDB = new AdminDBContext(); adminDB.admins.Add(admin); return(adminDB.SaveChanges()); } catch (Exception e) { //throw e; //LogUtil.writeLogToFile(e); return(-1); } }
public bool AddCourse(CourseDto courseDto) { try { var course = new Course { CourseName = courseDto.CourseName, Fee = courseDto.Fee, CTimings = courseDto.CTimings, CourseDesc = courseDto.CourseDesc }; context.Course.Add(course); int result = context.SaveChanges(); if (result > 0) { return(true); } return(false); } catch (Exception) { throw; } }
/* * Create By 蒋予飞 * 通过ID删除多个管理员 */ public int deleteAdminsByIds(string[] ids) { try { AdminDBContext adminDB = new AdminDBContext(); Admin admin; foreach (string id in ids) { admin = adminDB.admins.Find(id); adminDB.admins.Remove(admin); } return(adminDB.SaveChanges()); } catch (Exception e) { return(-1); } }
public ActionResult Create([Bind(Include = "SupplierName,ID,SupplierGroup,CompanyName,PhoneNumber,CellNumber,Email,password,BarCodeNumber,IDCardNumber,pictureURL,Published,Address")] SupplierModels supplierModels, HttpPostedFileBase filepicture) { ViewBag.CompanyNamelist = new SelectList(db.CompanyNameModels.ToList(), "CompanyName", "CompanyName"); ViewBag.SupplierGrouplist = new SelectList(db.SupplierGroupModels.ToList(), "GroupName", "GroupName"); if (ModelState.IsValid) { string subPath = "~/SupplierPic/" + supplierModels.SupplierName.ToString(); // your code goes here bool exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } if (filepicture != null) { var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", "jpeg" }; var fileName = Path.GetFileName(filepicture.FileName); var ext = Path.GetExtension(filepicture.FileName); //getting the extension(ex-.jpg) if (allowedExtensions.Contains(ext)) //check what type of extension { string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension string myfile = supplierModels.SupplierName + ext; //appending the name with id // store the file inside ~/project folder(Img) var path = Path.Combine(Server.MapPath("~/SupplierPic/" + supplierModels.SupplierName), myfile); supplierModels.pictureURL = Path.Combine("~/SupplierPic/" + supplierModels.SupplierName, myfile); filepicture.SaveAs(path); } } //////////// ApplicationDbContext context = new ApplicationDbContext(); var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context)); var RoleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context)); if (!RoleManager.RoleExists("Supplier")) { var roleresult = RoleManager.Create(new IdentityRole("Supplier")); } //Create User=Admin with password=123456 //var user = new ApplicationUser(); var user = new ApplicationUser { UserName = supplierModels.SupplierName, Email = supplierModels.Email, roleName = "Supplier" }; //user.UserName = "******";//supplierModels.SupplierName; //user.Email = supplierModels.Email; //user.roleName = "Supplier"; var adminresult = UserManager.Create(user, supplierModels.password); //Add User Admin to Role Admin if (adminresult.Succeeded) { var result = UserManager.AddToRole(user.Id, "Supplier"); } AddErrors(adminresult); ///////////////////////// try { db.SupplierModels.Add(supplierModels); db.SaveChanges(); } catch (DbUpdateException ex) { var sqlException = ex.InnerException.InnerException as SqlException; if (sqlException != null && sqlException.Number == 2627) { ModelState.AddModelError("", "Supplier already registered!"); } return(View(supplierModels)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message.ToString()); return(View(supplierModels)); } //////////// ///////////// return(RedirectToAction("Index")); } return(View(supplierModels)); }
public ActionResult Create([Bind(Include = "ID,LetterID,SupplierID,SupplierContact,Quantity,Deno,price,Date,QuoteDocURL,Other1DocURL,Other2DocURL,Other3DocURL,Other4DocURL")] SuplierUploadModels suplierUploadModels, HttpPostedFileBase fileQuoteDoc, HttpPostedFileBase fileOther1Doc, HttpPostedFileBase fileOther2Doc, HttpPostedFileBase fileOther3Doc, HttpPostedFileBase fileOther4Doc) { var denolist = new List <string>(); denolist.Add("NO"); denolist.Add("SET"); denolist.Add("L/I"); denolist.Add("LTR"); denolist.Add("MTR"); denolist.Add("LINE"); denolist.Add("CFT"); denolist.Add("PCS"); denolist.Add("PRS"); denolist.Add("SHT"); denolist.Add("KG"); denolist.Add("BOX"); denolist.Add("PKT"); denolist.Add("COPY"); denolist.Add("RM"); denolist.Add("Roll"); denolist.Add("Lbs"); denolist.Add("Bottle"); denolist.Add("Feet"); denolist.Add("Metric Ton"); denolist.Add("Other"); ViewBag.denolist = new SelectList(denolist); ViewBag.let = suplierUploadModels.LetterID; ViewBag.sup = suplierUploadModels.SupplierID; ViewBag.details = db.ProcurementAndTenderModels.Where(x => x.ID == suplierUploadModels.LetterID).Select(x => x.ItemDescription).FirstOrDefault(); ViewBag.quantity = db.ProcurementAndTenderModels.Where(x => x.ID == suplierUploadModels.LetterID).Select(x => x.Quantity).FirstOrDefault(); if (ModelState.IsValid) { string subPath = "~/SupplierUpload/" + suplierUploadModels.SupplierID + "/" + suplierUploadModels.LetterID.ToString() + "/" + "quote"; // your code goes here bool exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } if (fileQuoteDoc != null) { upload_file(fileQuoteDoc, suplierUploadModels, "quote", suplierUploadModels.LetterID); } //////// subPath = "~/SupplierUpload/" + suplierUploadModels.SupplierID + "/" + suplierUploadModels.LetterID.ToString() + "/" + "other1"; // your code goes here exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } if (fileOther1Doc != null) { upload_file(fileOther1Doc, suplierUploadModels, "other1", suplierUploadModels.LetterID); } //////// //////// subPath = "~/SupplierUpload/" + suplierUploadModels.SupplierID + "/" + suplierUploadModels.LetterID.ToString() + "/" + "other2"; // your code goes here exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } if (fileOther2Doc != null) { upload_file(fileOther2Doc, suplierUploadModels, "other2", suplierUploadModels.LetterID); } //////// //////// subPath = "~/SupplierUpload/" + suplierUploadModels.SupplierID + "/" + suplierUploadModels.LetterID.ToString() + "/" + "other3"; // your code goes here exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } if (fileOther3Doc != null) { upload_file(fileOther3Doc, suplierUploadModels, "other3", suplierUploadModels.LetterID); } //////// //////// subPath = "~/SupplierUpload/" + suplierUploadModels.SupplierID + "/" + suplierUploadModels.LetterID.ToString() + "/" + "other4"; // your code goes here exists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!exists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } if (fileOther4Doc != null) { upload_file(fileOther4Doc, suplierUploadModels, "other4", suplierUploadModels.LetterID); } //////// db.SuplierUploadModels.Add(suplierUploadModels); db.SaveChanges(); return(RedirectToAction("ProcurementFrontPage", "ProcurementAndTenderModels")); //return RedirectToAction("Index"); } return(View(suplierUploadModels)); }
public void AddStockExchange(StockExchange stockExchange) { context.Add(stockExchange); context.SaveChanges(); }