public IActionResult CreateModifyBicycle(BicycleEntryDetail item, int BicycleId) { int headerId = 0; string status = ""; string message = ""; string series = ""; string refno = ""; try { var _header = _context.BicycleEntryHeaders .Where(a => a.Status == "Active") .Where(a => a.BicycleId == BicycleId) .Where(a => a.DocumentStatus != "Approved").FirstOrDefault(); if (_header == null) { var comp = _context.Bicycles.Include(a => a.Departments.Companies) .Where(a => a.ID == BicycleId).FirstOrDefault().Departments.Companies.Code; if (comp == "SCPC") { comp = "SC"; } else { comp = "SL"; } string series_code = comp + "BICYCLE"; series = new NoSeriesController(_context).GetNoSeries(series_code); refno = comp + "BIC" + series; BicycleEntryHeader header = new BicycleEntryHeader { ReferenceNo = refno, BicycleId = BicycleId, CreatedAt = DateTime.Now.Date, CreatedBy = User.Identity.GetFullName() }; _context.Add(header); _context.SaveChanges(); string x = new NoSeriesController(_context).UpdateNoSeries(series, series_code); item.BicycleEntryHeaderId = header.Id; item.UpdatedBy = User.Identity.GetUserName(); item.UpdatedAt = DateTime.Now.Date; _context.Add(item); headerId = header.Id; } else { var d = _context.BicycleEntryDetails.Where(a => a.BicycleEntryHeaderId == _header.Id).FirstOrDefault(); d.BrakeRemarks = item.BrakeRemarks; d.BrakeSafe = item.BrakeSafe; d.BrakeUnSafe = item.BrakeUnSafe; d.ChainRemarks = item.ChainRemarks; d.ChainSafe = item.ChainSafe; d.ChainUnSafe = item.ChainUnSafe; d.CrankChainRemarks = item.CrankChainRemarks; d.CrankChainSafe = item.CrankChainSafe; d.CrankChainUnSafe = item.CrankChainUnSafe; d.FrameRemarks = item.FrameRemarks; d.FrameSafe = item.FrameSafe; d.FrameUnSafe = item.FrameUnSafe; d.FrontForkRemarks = item.FrontForkRemarks; d.FrontForkSafe = item.FrontForkSafe; d.FrontForkUnSafe = item.FrontForkUnSafe; d.FrontRearRemarks = item.FrontRearRemarks; d.FrontRearSafe = item.FrontRearSafe; d.FrontRearUnSafe = item.FrontRearUnSafe; d.HandlebarRemarks = item.HandlebarRemarks; d.HandlebarSafe = item.HandlebarSafe; d.HandlebarUnSafe = item.HandlebarUnSafe; d.SeatRemarks = item.SeatRemarks; d.SeatSafe = item.SeatSafe; d.SeatUnSafe = item.SeatUnSafe; d.InspectedBy = item.InspectedBy; d.NotedBy = item.NotedBy; d.UpdatedBy = User.Identity.GetUserName(); d.UpdatedAt = DateTime.Now.Date; _context.Entry(d).State = EntityState.Modified; _context.SaveChanges(); headerId = _header.Id; } _context.SaveChanges(); status = "success"; } catch (Exception ex) { headerId = 0; status = "failed"; message = ex.InnerException.Message; } var model = new { status , message, ReferenceId = headerId }; return(Json(model)); }
public async Task <IActionResult> saveSnapShot(string equipmenttype, int detailid) { string filename = ""; string status = ""; string message = ""; try { IFormFile file = Request.Form.Files[0]; string newFileName = DateTime.Now.Ticks + "_" + equipmenttype + Convert.ToString(detailid) + "_" + file.FileName; string filePath = ""; if (file.Length > 0) { string fullPath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\snapshots\", newFileName); using (var stream = new FileStream(fullPath, FileMode.Create)) { file.CopyTo(stream); stream.Position = 0; filename = stream.Name; } } switch (equipmenttype) { case "fe": var fe = _context.FireExtinguisherDetails.Find(detailid); //if (!string.IsNullOrEmpty(fe.ImageUrl)) //{ // filePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\snapshots\" + fe.ImageUrl); // System.IO.File.Delete(filePath); //} fe.ImageUrl = newFileName; _context.Entry(fe).State = EntityState.Modified; _context.SaveChanges(); break; case "el": var el = _context.EmergencyLightDetails.Find(detailid); //if (!string.IsNullOrEmpty(el.ImageUrl)) //{ // filePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\snapshots\" + el.ImageUrl); // System.IO.File.Delete(filePath); //} el.ImageUrl = newFileName; _context.Entry(el).State = EntityState.Modified; _context.SaveChanges(); break; case "it": var it = _context.InergenTankDetails.Find(detailid); //if (!string.IsNullOrEmpty(it.ImageUrl)) //{ // filePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\snapshots\" + it.ImageUrl); // System.IO.File.Delete(filePath); //} it.ImageUrl = newFileName; _context.Entry(it).State = EntityState.Modified; _context.SaveChanges(); break; case "fh": var fh = _context.FireHydrantDetails.Find(detailid); //if (!string.IsNullOrEmpty(fh.ImageUrl)) //{ // filePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\snapshots\" + fh.ImageUrl); // System.IO.File.Delete(filePath); //} fh.ImageUrl = newFileName; _context.Entry(fh).State = EntityState.Modified; _context.SaveChanges(); break; case "bc": var bc = _context.BicycleEntryDetails.Find(detailid); //if (!string.IsNullOrEmpty(fh.ImageUrl)) //{ // filePath = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\snapshots\" + fh.ImageUrl); // System.IO.File.Delete(filePath); //} bc.ImageUrl = newFileName; _context.Entry(bc).State = EntityState.Modified; _context.SaveChanges(); break; default: break; } status = "success"; } catch (Exception e) { status = "fail"; message = e.Message; e.Message.WriteLog(); } return(Json(null)); }
public IActionResult EnableDisableUser(string Domain, string UserName, string Email, string Status, string Name, string UserType) { string status = ""; string message = ""; try { if (Status == "Disabled") { var result = _context.Users.Where(b => b.Username == UserName).Where(b => b.Domain == Domain).FirstOrDefault(); if (result != null) { result.Email = Email; result.Status = "1"; _context.Entry(result).State = EntityState.Modified; _context.SaveChanges(); status = "success"; } else { User user = new User(); user.DepartmentId = 1; //Not set user.Username = UserName; user.Domain = Domain; user.Name = Name; user.Email = Email; user.Status = "1"; user.RoleId = 2; user.UserType = UserType; _context.Users.Add(user); _context.SaveChanges(); status = "success"; } } else { var result = _context.Users.Where(b => b.Username == UserName).Where(b => b.Domain == Domain).FirstOrDefault(); if (result != null) { result.Status = "0"; _context.Entry(result).State = EntityState.Modified; _context.SaveChanges(); } else { User user = new User(); user.DepartmentId = 1; //Not set user.Username = UserName; user.Domain = Domain; user.Name = Name; user.Status = "1"; user.RoleId = 2; user.UserType = UserType; _context.Users.Add(user); _context.SaveChanges(); } status = "success"; } } catch (Exception e) { status = "fail"; message = e.InnerException.InnerException.Message.ToString(); } var model = new { status, message }; return(Json(model)); }