public ActionResult Edit(Employee employee, HttpPostedFileBase file) { AssetLogic al = new AssetLogic(); if (ModelState.IsValid) { var _employee = _context.Employees.Find(employee.employeeNumber); if (file != null && file.ContentLength > 0) { employee.fileName = System.IO.Path.GetFileName(file.FileName); employee.fileType = file.ContentType; employee.fileBytes = al.ConvertToBytes(file); } else { employee.fileName = _employee.fileName; employee.fileType = _employee.fileType; employee.fileBytes = _employee.fileBytes; } employee.fullname = employee.firstName + " " + employee.lastName; _context.Entry(_employee).State = EntityState.Detached; _context.Entry(employee).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("UserProfile")); } ViewBag.RoleID = new SelectList(_context.Roles, "RoleID", "RoleName", employee.RoleID); ViewBag.departmentID = new SelectList(_context.Departments, "departmentID", "departmentName", employee.departmentID); return(View(employee)); }
public object InsertAsset(AssetReq Req) { try { //AssetsDBEntities DB=new AssetsDBEntities(); Request_assets R = new Request_assets(); if (R.RequestID == 0) { R.AssetName = Req.AssetName; R.Quantity = Req.Quantity; R.EmployeID = Req.EmployeID; R.Status = "Pending"; R.MgrID = Req.MgrID; DB.Request_assets.Add(R); DB.SaveChanges(); return(new Response { Status = "Success", Message = "Record SuccessFully Saved." }); } } catch (Exception) { throw; } return(new Response { Status = "Error", Message = "Invalid Data." }); }
public IHttpActionResult UpdateAssetAllocationDetails(int AssetAllocationId, int LastModifiedBy, string Comments) { AssetAllocation assetAllocation = new AssetAllocation(); assetAllocation = (from x in db.AssetAllocations where x.AssetAllocationId == AssetAllocationId select x).SingleOrDefault(); if (AssetAllocationId != assetAllocation.AssetAllocationId) { return(BadRequest()); } assetAllocation.LastModifiedBy = LastModifiedBy; assetAllocation.LastModifiedOn = System.DateTime.Now; assetAllocation.AssetCanceledOn = System.DateTime.Now; assetAllocation.CancellationComments = Comments; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AssetAllocationExists(AssetAllocationId)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PostAssetTypeSpecification(AssetTypeSpecification assetTypeSpecification) { assetTypeSpecification.CreatedBy = assetTypeSpecification.CreatedBy; assetTypeSpecification.CreatedOn = System.DateTime.Now; db.AssetTypeSpecifications.Add(assetTypeSpecification); db.SaveChanges(); string tt = "save"; return(Ok(tt)); }
public IHttpActionResult PostAssetCategory(AssetCategory assetCategory) { assetCategory.CreatedBy = assetCategory.CreatedBy; assetCategory.CreatedOn = System.DateTime.Now; assetCategory.IsActive = true; db.AssetCategories.Add(assetCategory); db.SaveChanges(); string tt = "save"; return(Ok(tt)); }
public ActionResult Create([Bind(Include = "ID,FirstName,LastName")] Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(employee)); }
public ActionResult Create(ReplacementPart replacementPart) { if (ModelState.IsValid) { db.ReplacementParts.Add(replacementPart); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(replacementPart)); }
public ActionResult Create([Bind(Include = "ID,Name,POID,StatusID,LicenseNo")] Software software) { if (ModelState.IsValid) { db.Softwares.Add(software); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID = new SelectList(db.PurchaseOrders, "ID", "PO_Number", software.ID); ViewBag.StatusID = new SelectList(db.Status, "ID", "Description", software.StatusID); return(View(software)); }
public object InsertAssets(AddAsset AA) { try { Asset A = new Asset(); int x; if (A.AssetID == 0) { A.AssetName = AA.AssetName; A.Quantity = AA.Quantity; A.Price = AA.Price; x = A.Quantity * A.Price; A.Total_Price = x; DB.Assets.Add(A); DB.SaveChanges(); return(new Response { Status = "Success", Message = "Asset SuccessFully Saved." }); } //else //{ // //Asset A = new Asset(); // var obj = DB.Assets.Where(z => z.AssetID == AA.AssetID).ToList().FirstOrDefault(); // int y; // if (obj.AssetID > 0) // { // obj.AssetName = AA.AssetName; // obj.Quantity = AA.Quantity; // obj.Price = AA.Price; // y = obj.Quantity * obj.Price; // obj.Total_Price = y; // //DB.Assets.Add(obj); // DB.SaveChanges(); // return new Response // { Status = "Success", Message = "Asset SuccessFully Saved." }; // } //} } catch (Exception) { throw; } return(new Response { Status = "Error", Message = "Invalid Data." }); }
public ActionResult Create([Bind(Include = "ID,EmployeeID,HardwareID,SoftwareID,StatusID,Comment")] Assignment assignment) { if (ModelState.IsValid) { db.Assignments.Add(assignment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "FirstName", assignment.EmployeeID); ViewBag.HardwareID = new SelectList(db.Hardwares, "ID", "Model", assignment.HardwareID); ViewBag.SoftwareID = new SelectList(db.Softwares, "ID", "Name", assignment.SoftwareID); return(View(assignment)); }
public ActionResult Create([Bind(Include = "ID,Type,Model,ServiceTag,POID,LabelName,StatusID")] Hardware hardware) { if (ModelState.IsValid) { db.Hardwares.Add(hardware); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.POID = new SelectList(db.PurchaseOrders, "ID", "PO_Number", hardware.POID); ViewBag.StatusID = new SelectList(db.Status, "ID", "Description", hardware.StatusID); ViewBag.Type = new SelectList(db.Types, "ID", "Description", hardware.Type); return(View(hardware)); }
public ActionResult Register(LoginRegisterViewModel model) { if (ModelState.IsValid) { if (Db.ApplicationUsers.Any(x => x.Email == model.RegisterEmail)) { var error = new ErrorViewModel { ErrorTitle = "Register Failed", ErrorMessage = "Your email is already existed! Try withh another email!" }; return(View("~/Views/Error/ErrorPage.cshtml", error)); } if (model.RegisterPassword != model.RetypePassword) { var error = new ErrorViewModel { ErrorTitle = "Register Failed", ErrorMessage = "Your password and retype password does not match" }; return(View("~/Views/Error/ErrorPage.cshtml", error)); } var user = new ApplicationUser { Firstname = model.Firstname, Lastname = model.Lastname, Country = model.Country, CreatedDate = DateTime.Now, Email = model.RegisterEmail, Password = model.RegisterPassword, Phone = model.Phone, RoleID = 2, StatusId = (int)EnumList.UserStatus.Active }; Db.ApplicationUsers.Add(user); Db.SaveChanges(); return(RedirectToAction("Index")); } return(View("~/Views/Account/Index.cshtml")); }
public JsonResult AssignLocation() { string json = Request.InputStream.ReadToEnd(); AssetLocationModel inputData = JsonConvert.DeserializeObject <AssetLocationModel>(json); bool success = false; string error = ""; AssetManagementEntities entities = new AssetManagementEntities(); try { //haetaan ensin paikan id-numero koodin perusteella int locationId = (from l in entities.Location where l.Code == inputData.LocationCode select l.LocationId).FirstOrDefault(); //haetaan ensin laitteen id-numero koodin perusteella int assetId = (from a in entities.Asset where a.Code == inputData.AssetCode select a.AssetId).FirstOrDefault(); if ((locationId > 0) && (assetId > 0)) { //tallennetaan uusi rivi aikaleiman kanssa kantaan AssetLocations newEntry = new AssetLocations(); newEntry.LocationId = locationId; newEntry.AssetId = assetId; newEntry.LastSeen = DateTime.Now; entities.AssetLocations.Add(newEntry); entities.SaveChanges(); success = true; } } catch (Exception ex) { error = ex.GetType().Name + ": " + ex.Message; } finally { entities.Dispose(); } //palautetaan JSON-muotoinen tulos kutsujalle var result = new { success = success, error = error }; return(Json(result)); }
public IHttpActionResult PostAssetQuotation() { long assetRequestId, vendorId, quantity = 0; decimal price, cgst, sgst; string comments = string.Empty; string status = string.Empty; string createdBy = string.Empty; try { HttpResponseMessage response = new HttpResponseMessage(); var httpRequest = HttpContext.Current.Request; assetRequestId = Convert.ToInt64(httpRequest.Form["EntityTypeId"]); vendorId = Convert.ToInt64(httpRequest.Form["VendorId"]); quantity = Convert.ToInt64(httpRequest.Form["Quantity"]); price = Convert.ToDecimal(httpRequest.Form["Price"]); comments = httpRequest.Form["Comments"]; cgst = Convert.ToDecimal(httpRequest.Form["CGST"]); sgst = Convert.ToDecimal(httpRequest.Form["SGST"]); createdBy = httpRequest.Form["CreatedBy"]; var assetVendor = db.AssetQuotations.Where(x => x.AssetVendorId == vendorId && x.AssetRequestId == assetRequestId && x.IsActive == true).Select(x => x.Id).FirstOrDefault(); if (assetVendor == 0) { if (httpRequest.Form.Keys.Count > 0) { AssetQuotation assetQuotation = new AssetQuotation(); assetQuotation.AssetRequestId = assetRequestId; assetQuotation.AssetVendorId = vendorId; assetQuotation.Price = price; assetQuotation.Quantity = quantity; assetQuotation.Comments = (comments == "undefined") ? string.Empty : comments; assetQuotation.Documents = ""; assetQuotation.CGST = cgst; assetQuotation.SGST = sgst; assetQuotation.IsActive = true; assetQuotation.CreatedOn = System.DateTime.Now; assetQuotation.CreatedBy = (createdBy == "undefined") ? 0 : Convert.ToInt16(createdBy); db.AssetQuotations.Add(assetQuotation); db.SaveChanges(); var fileUpload = new AssetDocumentsController(); var result = fileUpload.FileUpload(assetQuotation.Id, Convert.ToInt16(createdBy)); status = "success"; } } else { status = "exist"; } } catch (Exception) { throw; } return(Ok(status)); }
public ActionResult Create([Bind(Include = "ticketid,assetnumber,assetowner,subject,priority,description,accomplishstatus,acknowledgestatus,ticketstatus,datecreated,datedue,employeeNumber")] Ticket ticket) { ticket.accomplishstatus = false; ticket.acknowledgestatus = false; ticket.ticketstatus = true; ticket.datecreated = DateTime.Now; if (ModelState.IsValid) { var asset = _context.Assets.FirstOrDefault(e => e.assetNumber.Equals(ticket.assetnumber)); if (asset != null) { ticket.assetid = asset.assetID; _context.Tickets.Add(ticket); _context.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.employeeNumber = new SelectList(_context.Employees.ToList().Where(x => x.position.Equals("Technician") || x.position.Equals("Administrator")), "employeeNumber", "fullname", ticket.employeeNumber); return(View(ticket)); }
public ActionResult Ticket(string id, string solution) { var _context = new AssetManagementEntities(); var ticket = _context.Tickets.Find(int.Parse(id)); ticket.datecompleted = DateTime.Now; ticket.accomplishstatus = true; ticket.ticketstatus = true; ticket.solution = solution; _context.Entry(ticket).State = EntityState.Modified; _context.SaveChanges(); TempData["Success"] = "Ticket has been completed"; return(RedirectToAction("Ticket")); }
public void comment(string id, string comment) { if (id != null) { var _context = new AssetManagementEntities(); var ticket = _context.Tickets.Find(int.Parse(id)); var name = _context.Employees.Single(e => e.employeeNumber == User.Identity.Name); var progress = new Progress { ticketid = ticket.ticketid, comment = comment, date = DateTime.Now, employeeNumber = User.Identity.Name, employeeName = name.fullname }; _context.Progresses.Add(progress); _context.SaveChanges(); } }
public IHttpActionResult FileUpload(long entityTypeId, int CreatedBy) { //long entityTypeId; string entityName = string.Empty; var httpRequest = HttpContext.Current.Request; //entityTypeId = Convert.ToInt64(httpRequest.Form["EntityTypeId"]); entityName = httpRequest.Form["Entity"]; if (httpRequest.Files.Count > 0 && httpRequest.Form.Keys.Count > 0) { var entityId = db.Entities.Where(x => x.EntityName == entityName).Select(y => y.EntityId).FirstOrDefault(); fileLocation = fileLocation + "/" + entityId + "/" + entityTypeId + "/"; if (!Directory.Exists(fileLocation)) { Directory.CreateDirectory(fileLocation); } foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; var filePath = fileLocation + postedFile.FileName; postedFile.SaveAs(filePath); var assetDocument = new AssetDocument(); assetDocument.EntityId = entityId; assetDocument.EntityTypeId = entityTypeId; assetDocument.FilePath = fileLocation; assetDocument.FileName = postedFile.FileName; assetDocument.IsActive = true; assetDocument.CreatedOn = System.DateTime.Now; assetDocument.CreatedBy = CreatedBy; //assetDocument.FileUpload = FileUpload; db.AssetDocuments.Add(assetDocument); } db.SaveChanges(); } return(Ok("success")); }
public ActionResult WriteComment(int?id, string comment) { var _context = new AssetManagementEntities(); if (id != null) { var ticket = _context.Tickets.Find(id); var name = _context.Employees.Single(e => e.employeeNumber == User.Identity.Name); var progress = new Progress { ticketid = ticket.ticketid, comment = comment, date = DateTime.Now, employeeNumber = User.Identity.Name, employeeName = name.fullname }; _context.Progresses.Add(progress); _context.SaveChanges(); return(RedirectToAction("Ticket", new { id = ticket.ticketid.ToString() })); } return(View()); }
public ActionResult Add(StockViewModel viewmodel) { if (ModelState.IsValid) { try { Stock stck = context.Stocks.FirstOrDefault(x => x.model.Equals(viewmodel.Model) && x.manufacturer.Equals(viewmodel.Manaufacturer) && x.category.Equals(viewmodel.Catergory)); if (stck != null) { stck.quantity = stck.quantity + (Convert.ToInt32(viewmodel.Quantity)); context.SaveChanges(); TempData["Success"] = "Asset stock has been updated!"; return(View()); } else { var stock = new Stock { category = viewmodel.Catergory, model = viewmodel.Model, manufacturer = viewmodel.Manaufacturer, quantity = Convert.ToInt32(viewmodel.Quantity) }; repo.Insert(stock); repo.Save(); } TempData["Success"] = "New asset stock has been added!"; } catch (Exception e) { ViewBag.Message = "Asset stock not added. Error: " + e.Message; } } ModelState.Clear(); return(View()); }
// post: Materialize public IHttpActionResult PostMaterializePo(int AssetRequestId) { string AssetStatus = "Materialized"; var dbAssetStatusId = db.AssetStatus.Where(c => c.Name.ToUpper() == AssetStatus.ToUpper()).Select(x => x.Id).FirstOrDefault(); AssetRequest assetRequest = (from x in db.AssetRequests where x.Id == AssetRequestId select x).Single(); if (assetRequest != null) { assetRequest.AssetStatusId = dbAssetStatusId; assetRequest.LastModifiedOn = System.DateTime.Now; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } } return(Ok()); }
public IHttpActionResult ChangePassword(UserModel userPasswordDetail) { long userId = Convert.ToInt64(userPasswordDetail.UserId); var userDetail = (from e in db.Employees join u in db.Users on e.UserId equals u.EmployeeUserId where e.UserId == userId && u.Password.Replace(" ", "#") == userPasswordDetail.Password.Replace(" ", "#") select u).SingleOrDefault(); if (userDetail == null) { return(Ok("fail")); } userDetail.Password = userPasswordDetail.NewPassword; try { db.SaveChanges(); return(Ok("success")); } catch (DbUpdateConcurrencyException) { throw; } }
public ActionResult Add(MouseViewModel viewmodel) { ViewBag.LM = db.Stocks.ToList().Where(x => x.category == "Mouse"); List <Stock> slist = new List <Stock>(db.Stocks.ToList().Where(x => x.category == "Mouse")); List <SelectListItem> li = new List <SelectListItem>(); foreach (var item in slist) { var man = li.Find(x => x.Value == item.manufacturer); if (man == null) { li.Add(new SelectListItem { Text = item.manufacturer, Value = item.manufacturer }); } } ViewBag.MouseM = li; if (ModelState.IsValid) { try { var stock = db.Stocks.FirstOrDefault(m => m.model.Equals(viewmodel.modelName) && m.manufacturer.Equals(viewmodel.manufacturer) && m.category.Equals("Mouse")); if (stock != null && stock.quantity != 0) { AssetLogic al = new AssetLogic(); var asset = new Asset { manufacturer = viewmodel.manufacturer, serialNumber = viewmodel.serialNumber, dateadded = viewmodel.dateAdded, warranty = viewmodel.warranty + " Months", costprice = viewmodel.costprice, InvoiceNumber = viewmodel.InvoiceNumber, depreciationcost = al.depreciationCost(viewmodel.dateAdded, viewmodel.costprice) }; var mouse = new Mouse { serialNumber = viewmodel.serialNumber, manufacturer = viewmodel.manufacturer, modelName = viewmodel.modelName, warranty = viewmodel.warranty + " Months", dateAdded = viewmodel.dateAdded, InvoiceNumber = viewmodel.InvoiceNumber }; stock.quantity = stock.quantity - 1; _repository.Insert(asset, mouse); _repository.Save(); db.SaveChanges(); TempData["Success"] = "Asset has been added!"; ModelState.Clear(); } else { ViewBag.Message = "Asset model not available in stock. Update your stock."; } } catch (Exception e) { ViewBag.Message = "Asset not added. Error: " + e.Message; } } return(View(viewmodel)); }
public void AddReplacementPart(ReplacementPart part) { _context.ReplacementParts.Add(part); _context.SaveChanges(); }
// POST api/RaiseRequest public IHttpActionResult PostAssetQuoteApproval() { long assetQuotationId, entityTypeId; int loginId; string comments, status = string.Empty, PONumber = string.Empty, sdate = string.Empty; bool isAwaitingNextApproval; long dbMaxPONumber = 0; try { HttpResponseMessage response = new HttpResponseMessage(); var httpRequest = HttpContext.Current.Request; assetQuotationId = Convert.ToInt64(httpRequest.Form["AssetQuotationId"]); comments = httpRequest.Form["Comments"]; isAwaitingNextApproval = Convert.ToBoolean(httpRequest.Form["IsAwaitingNextApproval"]); loginId = Convert.ToInt32(httpRequest.Form["LoginId"]); entityTypeId = Convert.ToInt64(httpRequest.Form["EntityTypeId"]); string AssetStatus = string.Empty; bool IsAwaitingNxtApproval = false; if (isAwaitingNextApproval == true) { IsAwaitingNxtApproval = true; AssetStatus = "Awaiting Quotation Approval"; } else { AssetStatus = "Awaiting PO"; } var dbAssetStatusId = db.AssetStatus.Where(c => c.Name.ToUpper() == AssetStatus.ToUpper()).Select(x => x.Id).FirstOrDefault(); var dbAssetRequestId = db.AssetQuotations.Where(c => c.Id == assetQuotationId).Select(x => x.AssetRequestId).FirstOrDefault(); AssetQuoteApproval assetQuoteApproval = new AssetQuoteApproval(); assetQuoteApproval.AssetQuotationId = assetQuotationId; assetQuoteApproval.ApprovedBy = loginId; //Need to modify assetQuoteApproval.ApprovedOn = System.DateTime.Now; assetQuoteApproval.IsAwaitingNextApproval = IsAwaitingNxtApproval; assetQuoteApproval.Comments = comments; assetQuoteApproval.CreatedBy = loginId; assetQuoteApproval.CreatedOn = System.DateTime.Now; db.AssetQuoteApprovals.Add(assetQuoteApproval); if (httpRequest.Form.Keys.Count > 0) { var fileUpload = new AssetDocumentsController(); var result = fileUpload.FileUpload(entityTypeId, loginId); } db.SaveChanges(); var assetRequest = db.AssetRequests.SingleOrDefault(x => x.Id == dbAssetRequestId); // Add the PO Number exists in AssetRequest table sdate = DateTime.Now.ToShortDateString().Replace(@"-", ""); dbMaxPONumber = db.AssetRequests.Where(a => a.PONumber != null).Count(); dbMaxPONumber = dbMaxPONumber + 1; PONumber = "PO_" + dbMaxPONumber + "_" + sdate; if (assetRequest != null) { assetRequest.AssetQuotationId = assetQuotationId; assetRequest.PONumber = PONumber; assetRequest.AssetStatusId = dbAssetStatusId; assetRequest.LastModifiedOn = System.DateTime.Now; db.SaveChanges(); } status = "success"; AssetHistory assetHistory = new AssetHistory(); assetHistory.AssetRequestId = Convert.ToInt32(dbAssetRequestId); assetHistory.TargetStatusId = dbAssetStatusId; assetHistory.StatusChangedBy = loginId; assetHistory.StatusModifiedOn = System.DateTime.Now; assetHistory.Comments = comments; db.AssetHistories.Add(assetHistory); db.SaveChanges(); } catch (Exception) { throw; } return(Ok(status)); }
public ActionResult Add(LaptopViewModel viewmodel, string modelName) { ViewBag.LM = context.Stocks.ToList().Where(x => x.category == "Laptop"); List <Stock> slist = new List <Stock>(context.Stocks.ToList().Where(x => x.category == "Laptop")); List <SelectListItem> li = new List <SelectListItem>(); foreach (var item in slist) { var man = li.Find(x => x.Value == item.manufacturer); if (man == null) { li.Add(new SelectListItem { Text = item.manufacturer, Value = item.manufacturer }); } } viewmodel.modelName = modelName; ViewBag.LL = li; ViewBag.LM = context.Stocks.ToList().Where(x => x.category == "Laptop"); if (ModelState.IsValid) { AssetLogic al = new AssetLogic(); try { Stock stock = context.Stocks.FirstOrDefault(m => m.model.Equals(viewmodel.modelName) && m.manufacturer.Equals(viewmodel.manufacturer) && m.category.Equals("Laptop")); if (stock != null && stock.quantity != 0) { var asset = new Asset { manufacturer = viewmodel.manufacturer, serialNumber = viewmodel.serialNumber, dateadded = viewmodel.dateAdded, warranty = viewmodel.warranty + " Months", costprice = viewmodel.costprice, InvoiceNumber = viewmodel.InvoiceNumber, depreciationcost = al.depreciationCost(viewmodel.dateAdded, viewmodel.costprice) }; var laptop = new Laptop { serialNumber = viewmodel.serialNumber, manufacturer = viewmodel.manufacturer, modelName = viewmodel.modelName, warranty = viewmodel.warranty + " Months", dateAdded = viewmodel.dateAdded, HDD = viewmodel.HDD, OS = viewmodel.OS, RAM = viewmodel.RAM, screenSize = viewmodel.screenSize, InvoiceNumber = viewmodel.InvoiceNumber, processor = viewmodel.processor }; stock.quantity = stock.quantity - 1; repository.Insert(asset, laptop); repository.Save(); context.SaveChanges(); TempData["Success"] = "Asset has been added!"; } else { ViewBag.Message = "Asset model not available in stock. Update your stock."; } } catch (Exception e) { ViewBag.Message = "Asset not added. Error: " + e.Message; } } ModelState.Clear(); return(View(viewmodel)); }