Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("ID,Code,Name,Status,CompanyId")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();


                Log log = new Log
                {
                    Descriptions = "Create Department - " + department.ID,
                    Action       = "Create",
                    Status       = "success",
                    UserId       = User.Identity.GetUserName()
                };
                _context.Add(log);

                _context.SaveChanges();



                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CompanyId"] = new SelectList(_context.Companies, "ID", "Name", department.CompanyId);
            return(View(department));
        }
Esempio n. 2
0
        public string GetNoSeries(string Code)
        {
            string str    = "";
            int    number = 0;

            try
            {
                //new setup for num series
                string lno = _context.NoSeries.Where(i => i.Code == Code).Select(n => n.LastNoUsed).FirstOrDefault();
                if (lno == null)
                {
                    var ns = new NoSeries
                    {
                        Code        = Code,
                        LastNoUsed  = "00000",
                        DateCreated = DateTime.Now.Date,
                        DateUpdated = DateTime.Now.Date
                    };
                    _context.Add(ns);
                    _context.SaveChanges();

                    number = 0;
                }
                else
                {
                    number = Convert.ToInt32(lno);
                }


                number += 1;

                str = number.ToString("D5");
            }
            catch (Exception e)
            {
                throw;
            }


            return(str);
        }
Esempio n. 3
0
        public async Task <IActionResult> Create(Company company)
        {
            if (ModelState.IsValid)
            {
                _context.Add(company);
                await _context.SaveChangesAsync();

                Log log = new Log
                {
                    Descriptions = "Create Company - " + company.ID,
                    Action       = "Create",
                    Status       = "success",
                    UserId       = User.Identity.GetUserName()
                };
                _context.Add(log);

                _context.SaveChanges();



                return(RedirectToAction(nameof(Index)));
            }
            return(View(company));
        }
Esempio n. 4
0
        public IActionResult getData()
        {
            var yearDate = DateTime.Now.Date;


            var _itemForRefill = _context.Items
                                 .Where(a => a.EquipmentType == "Fire Extinguisher")
                                 .Where(a => a.Status == "Active")
                                 .Where(a => a.ItemStatus != "For Refill")
                                 .Where(a => a.DatePurchased.Value.Date.AddMonths(12) <= yearDate)
                                 .ToList();

            if (_itemForRefill.Count() > 0)
            {
                _itemForRefill.ForEach(a =>
                {
                    a.ItemStatus = "For Refill";
                }
                                       );
                _context.SaveChanges();
            }


            string status = "";
            var    v      =
                _context.Items
                .Where(a => a.Status != "Deleted")
                .Select(a => new {
                a.Code,
                a.Name,
                a.DatePurchased,
                a.ItemStatus,
                a.Warranty,
                a.SerialNo,
                a.Id,
                a.EquipmentType
            });

            status = "success";

            var model = new
            {
                status
                ,
                data = v
            };

            return(Json(model));
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        public IActionResult SaveData(FireExtinguisherViewModel[] item)
        {
            int    headerId = 0;
            string status   = "";
            string message  = "";

            string series = "";
            string refno  = "";

            //string series_code = "INERGENTANK";
            //series = new NoSeriesController(_context).GetNoSeries(series_code);
            //refno = "IT" + series;


            try
            {
                //var _header = _context.InergenTankHeaders.Where(a => a.Status == "Active")
                //      //.Where(a => a.AreaId == item[0].AreaId)
                //    .Where(a => a.LocationInergenTankId == item[0].LocationInergenTankId)
                //    .Where(a => a.CreatedAt == DateTime.Now.Date);
                var _header = _context.InergenTankHeaders
                              .Where(a => a.AreaId == item[0].AreaId)
                              .Where(a => a.Status == "Active")
                              .Where(a => a.DocumentStatus != "Approved");
                if (_header.Count() == 0)
                {
                    var comp = _context.LocationInergenTanks.Include(a => a.Areas.Companies).Where(a => a.Id == item[0].LocationInergenTankId)
                               .FirstOrDefault().Areas.Companies.Code;

                    if (comp == "SCPC")
                    {
                        comp = "SC";
                    }
                    else
                    {
                        comp = "SL";
                    }
                    string series_code = comp + "INERGENTANK";
                    series = new NoSeriesController(_context).GetNoSeries(series_code);
                    refno  = comp + "IT" + series;


                    InergenTankHeader header = new InergenTankHeader
                    {
                        ReferenceNo = refno,
                        AreaId      = item[0].AreaId,
                        CreatedAt   = DateTime.Now.Date,
                        CreatedBy   = User.Identity.GetFullName()
                    };
                    _context.Add(header);
                    _context.SaveChanges();
                    headerId = header.Id;

                    string x = new NoSeriesController(_context).UpdateNoSeries(series, series_code);



                    foreach (var detail in item)
                    {
                        var _detail = new InergenTankDetail
                        {
                            ItemId = detail.ItemId,

                            Cylinder = Convert.ToInt32(detail.Cylinder),
                            Gauge    = Convert.ToInt32(detail.Gauge),
                            Hose     = Convert.ToInt32(detail.Hose),
                            Pressure = Convert.ToInt32(detail.Pressure),

                            CreatedAt             = DateTime.Now.Date,
                            UpdatedAt             = DateTime.Now.Date,
                            InergenTankHeaderId   = headerId,
                            Remarks               = detail.Remarks,
                            InspectedBy           = detail.InspectedBy,
                            ReviewedBy            = detail.ReviewedBy,
                            NotedBy               = detail.NotedBy,
                            LocationInergenTankId = detail.LocationInergenTankId,
                        };

                        _context.Add(_detail);
                    }
                }
                else
                {
                    //headerId = item[0].ID;
                    headerId = _header.FirstOrDefault().Id;
                    foreach (var detail in item)
                    {
                        var d = _context.InergenTankDetails
                                .Where(a => a.InergenTankHeaderId == headerId)
                                .Where(a => a.LocationInergenTankId == detail.LocationInergenTankId)
                                .Where(a => a.ItemId == detail.ItemId)
                                .FirstOrDefault();

                        if (d == null)
                        {
                            var _detail = new InergenTankDetail
                            {
                                ItemId   = detail.ItemId,
                                Cylinder = Convert.ToInt32(detail.Cylinder),
                                Gauge    = Convert.ToInt32(detail.Gauge),
                                Hose     = Convert.ToInt32(detail.Hose),
                                Pressure = Convert.ToInt32(detail.Pressure),

                                CreatedAt             = DateTime.Now.Date,
                                UpdatedAt             = DateTime.Now,
                                InergenTankHeaderId   = headerId,
                                Remarks               = detail.Remarks,
                                InspectedBy           = detail.InspectedBy,
                                ReviewedBy            = detail.ReviewedBy,
                                NotedBy               = detail.NotedBy,
                                LocationInergenTankId = detail.LocationInergenTankId,
                            };

                            _context.Add(_detail);
                        }
                        else
                        {
                            d.Cylinder = Convert.ToInt32(detail.Cylinder);
                            d.Gauge    = Convert.ToInt32(detail.Gauge);
                            d.Hose     = Convert.ToInt32(detail.Hose);
                            d.Pressure = Convert.ToInt32(detail.Pressure);

                            d.UpdatedAt             = DateTime.Now;
                            d.UpdatedBy             = User.Identity.GetUserName();
                            d.InergenTankHeaderId   = headerId;
                            d.Remarks               = detail.Remarks;
                            d.InspectedBy           = detail.InspectedBy;
                            d.ReviewedBy            = detail.ReviewedBy;
                            d.NotedBy               = detail.NotedBy;
                            d.LocationInergenTankId = detail.LocationInergenTankId;
                            _context.Update(d);
                        }
                        _context.SaveChanges();
                    }
                }



                _context.SaveChanges();
                status = "success";
            }
            catch (Exception ex)
            {
                status  = "failed";
                message = ex.InnerException.Message;
            }



            var model = new
            {
                status
                ,
                message,
                ReferenceId = headerId
            };

            return(Json(model));
        }
Esempio n. 7
0
        private string SendEmail(NotifyViewModel nvm)
        {
            string email = "";

            string message       = "";
            string rply          = "";
            string revieweremail = "";
            string approveremail = "*****@*****.**";
            //string approveremail = "*****@*****.**";
            string recipient = "";


            try
            {
                switch (nvm.DocumentStatus)
                {
                case "For Review":
                    if (nvm.CompanyId == 1)     //slpgc
                    {
                        ////gbarroyo
                        revieweremail = "*****@*****.**";
                        //revieweremail = "*****@*****.**";
                    }
                    else
                    {
                        ////eccueto
                        revieweremail = "*****@*****.**";
                        //revieweremail = "*****@*****.**";
                    }
                    message = "There's a form For Review for area " + nvm.Area + " with Reference No: " + nvm.ReferenceNo;
                    break;

                case "For Approval":
                    message = "There's a form For Approval for area " + nvm.Area + " with Reference No: " + nvm.ReferenceNo;
                    break;

                default:
                    break;
                }



                string msg = "Hi, <br /><br />" + message + " <br /><br />";

                var         body = msg;
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("*****@*****.**", "Safety Equipment Monitoring System");


                if (nvm.DocumentStatus == "For Review")
                {
                    mail.To.Add(new MailAddress(revieweremail));
                    //mail.To.Add(new MailAddress("*****@*****.**"));
                    recipient = revieweremail;
                }
                else
                {
                    mail.To.Add(new MailAddress(approveremail));

                    recipient = approveremail;
                }
                mail.Bcc.Add(new MailAddress("*****@*****.**"));
                mail.Bcc.Add(new MailAddress("*****@*****.**"));


                mail.Subject    = "Safety Equipment Monitoring System" + " - " + nvm.DocumentStatus.ToUpper();
                mail.Body       = string.Format(body + " Click on this link to view details. http://192.168.30.182/SEM/");
                mail.IsBodyHtml = true;

                using (var smtp = new SmtpClient()) //mail server
                {
                    try
                    {
                        smtp.Host        = "mail.cpcaccess.com";
                        smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "System@1");
                        smtp.Port        = 587;
                        smtp.EnableSsl   = false;
                        smtp.Send(mail);
                        rply = "success";
                    }
                    catch (Exception e)
                    {
                        WriteLog(e.Message);
                        rply = e.Message;
                    }
                }
            }
            catch (Exception e)
            {
                WriteLog(e.Message);
                rply = e.Message.ToString();
            }

            Log log = new Log();

            log.Action       = "Send Email";
            log.Descriptions = "Send EMAIL by Header Referenceno : " + nvm.ReferenceNo + ", Recipient : " + recipient;
            log.Status       = rply;
            //log.UserId = User.Identity.GetUserName();
            _context.Logs.Add(log);
            _context.SaveChanges();

            return(rply);
        }
Esempio n. 8
0
        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 IActionResult SaveData(EmergencyLightViewModel[] item)
        {
            int    headerId = 0;
            string status   = "";
            string message  = "";

            string series = "";
            string refno  = "";

            //string series_code = "EMERGENCYLIGHT";
            //series = new NoSeriesController(_context).GetNoSeries(series_code);
            //refno = "EL" + series;


            try
            {
                //var _header = _context.EmergencyLightHeaders
                //    .Where(a => a.Status == "Active")
                //    .Where(a => a.LocationEmergencyLightId == item[0].LocationEmergencyLightId)
                //    .Where(a => a.CreatedAt == DateTime.Now.Date);

                var _header = _context.EmergencyLightHeaders
                              .Where(a => a.AreaId == item[0].AreaId)
                              .Where(a => a.Status == "Active")
                              .Where(a => a.DocumentStatus != "Approved");

                if (_header.Count() == 0)
                {
                    var comp = _context.LocationEmergencyLights.Include(a => a.Areas.Companies).Where(a => a.Id == item[0].LocationEmergencyLightId).FirstOrDefault()
                               .Areas.Companies.Code;
                    if (comp == "SCPC")
                    {
                        comp = "SC";
                    }
                    else
                    {
                        comp = "SL";
                    }
                    string series_code = comp + "EMERGENCYLIGHT";
                    series = new NoSeriesController(_context).GetNoSeries(series_code);
                    refno  = comp + "EL" + series;


                    EmergencyLightHeader header = new EmergencyLightHeader
                    {
                        //header.AreaId = item[0].AreaId;
                        ReferenceNo = refno,
                        AreaId      = item[0].AreaId,
                        CreatedAt   = DateTime.Now.Date,
                        CreatedBy   = User.Identity.GetFullName()
                    };
                    _context.Add(header);
                    _context.SaveChanges();
                    headerId = header.Id;
                    string x = new NoSeriesController(_context).UpdateNoSeries(series, series_code);

                    foreach (var detail in item)
                    {
                        var _detail = new EmergencyLightDetail
                        {
                            ItemId  = detail.ItemId,
                            Battery = Convert.ToInt32(detail.Battery),
                            Bulb    = Convert.ToInt32(detail.Bulb),
                            Usable  = Convert.ToInt32(detail.Usable),

                            CreatedAt = DateTime.Now.Date,
                            UpdatedAt = DateTime.Now.Date,
                            EmergencyLightHeaderId = headerId,
                            Remarks = detail.Remarks,

                            InspectedBy = detail.InspectedBy,
                            ReviewedBy  = detail.ReviewedBy,
                            NotedBy     = detail.NotedBy,
                            LocationEmergencyLightId = detail.LocationEmergencyLightId
                        };

                        _context.Add(_detail);
                    }
                }
                else
                {
                    headerId = _header.FirstOrDefault().Id;

                    foreach (var detail in item)
                    {
                        var d = _context.EmergencyLightDetails
                                .Where(a => a.EmergencyLightHeaderId == headerId)
                                .Where(a => a.LocationEmergencyLightId == detail.LocationEmergencyLightId)
                                .Where(a => a.ItemId == detail.ItemId)
                                .FirstOrDefault();

                        if (d == null)
                        {
                            var _detail = new EmergencyLightDetail
                            {
                                ItemId  = Convert.ToInt32(detail.ItemId),
                                Battery = Convert.ToInt32(detail.Battery),
                                Bulb    = Convert.ToInt32(detail.Bulb),
                                Usable  = Convert.ToInt32(detail.Usable),

                                CreatedAt = DateTime.Now.Date,
                                UpdatedAt = DateTime.Now,
                                EmergencyLightHeaderId = headerId,
                                Remarks = detail.Remarks,

                                InspectedBy = detail.InspectedBy,
                                ReviewedBy  = detail.ReviewedBy,
                                NotedBy     = detail.NotedBy,
                                LocationEmergencyLightId = detail.LocationEmergencyLightId,
                            };

                            _context.Add(_detail);
                        }
                        else
                        {
                            d.Battery = Convert.ToInt32(detail.Battery);
                            d.Bulb    = Convert.ToInt32(detail.Bulb);
                            d.Usable  = Convert.ToInt32(detail.Usable);

                            d.UpdatedAt = DateTime.Now;
                            d.UpdatedBy = User.Identity.GetUserName();
                            d.EmergencyLightHeaderId = headerId;
                            d.Remarks     = detail.Remarks;
                            d.InspectedBy = detail.InspectedBy;
                            d.ReviewedBy  = detail.ReviewedBy;
                            d.NotedBy     = detail.NotedBy;
                            d.LocationEmergencyLightId = detail.LocationEmergencyLightId;
                            _context.Update(d);
                        }
                        _context.SaveChanges();
                    }
                }



                _context.SaveChanges();
                status = "success";
            }
            catch (Exception ex)
            {
                status  = "failed";
                message = ex.InnerException.Message;
            }



            var model = new
            {
                status
                ,
                message,
                ReferenceId = headerId
            };

            return(Json(model));
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        public IActionResult SaveData(FireHydrantViewModel[] item)
        {
            string series = "";
            string refno  = "";
            //string series_code = "FIREHYDRANT";
            //series = new NoSeriesController(_context).GetNoSeries(series_code);
            //refno = "FH" + series;

            int    headerId = 0;
            string status   = "";
            string message  = "";

            try
            {
                //var _header = _context.FireHydrantHeaders.Where(a => a.Status == "Active")
                //// .Where(a => a.AreaId == item[0].AreaId)
                //.Where(a => a.LocationFireHydrantId == item[0].LocationFireHydrantId)
                //.Where(a => a.CreatedAt == DateTime.Now.Date);

                var _header = _context.FireHydrantHeaders
                              .Where(a => a.AreaId == item[0].AreaId)
                              .Where(a => a.Status == "Active")
                              .Where(a => a.DocumentStatus != "Approved");

                if (_header.Count() == 0)
                {
                    var comp = _context.LocationFireHydrants.Include(a => a.Areas.Companies).Where(a => a.Id == item[0].LocationFireHydrantId).FirstOrDefault()
                               .Areas.Companies.Code;
                    if (comp == "SCPC")
                    {
                        comp = "SC";
                    }
                    else
                    {
                        comp = "SL";
                    }
                    string series_code = comp + "FIREHYDRANT";
                    series = new NoSeriesController(_context).GetNoSeries(series_code);
                    refno  = comp + "FH" + series;


                    FireHydrantHeader header = new FireHydrantHeader
                    {
                        ReferenceNo = refno,
                        //LocationFireHydrantId = item[0].LocationFireHydrantId,
                        AreaId    = item[0].AreaId,
                        CreatedAt = DateTime.Now.Date,
                        CreatedBy = User.Identity.GetFullName()
                    };
                    _context.Add(header);
                    _context.SaveChanges();
                    string x = new NoSeriesController(_context).UpdateNoSeries(series, series_code);
                    headerId = header.Id;

                    foreach (var detail in item)
                    {
                        var _detail = new FireHydrantDetail
                        {
                            ItemId                = detail.ItemId,
                            GlassCabinet          = Convert.ToInt32(detail.GlassCabinet),
                            Hanger                = Convert.ToInt32(detail.Hanger),
                            Hose15                = Convert.ToInt32(detail.Hose15),
                            Nozzle15              = Convert.ToInt32(detail.Nozzle15),
                            Hose25                = Convert.ToInt32(detail.Hose25),
                            Nozzle25              = Convert.ToInt32(detail.Nozzle25),
                            SpecialTools          = Convert.ToInt32(detail.SpecialTools),
                            InspectedBy           = detail.InspectedBy,
                            ReviewedBy            = detail.ReviewedBy,
                            NotedBy               = detail.NotedBy,
                            CreatedAt             = DateTime.Now.Date,
                            UpdatedAt             = DateTime.Now.Date,
                            FireHydrantHeaderId   = headerId,
                            Remarks               = detail.Remarks,
                            LocationFireHydrantId = detail.LocationFireHydrantId,
                        };

                        _context.Add(_detail);
                    }
                }
                else
                {
                    headerId = _header.FirstOrDefault().Id;

                    foreach (var detail in item)
                    {
                        var d = _context.FireHydrantDetails
                                .Where(a => a.FireHydrantHeaderId == headerId)
                                .Where(a => a.LocationFireHydrantId == item[0].LocationFireHydrantId)
                                .Where(a => a.ItemId == detail.ItemId)
                                .FirstOrDefault();

                        if (d == null)
                        {
                            var _detail = new FireHydrantDetail
                            {
                                ItemId = detail.ItemId,


                                GlassCabinet = Convert.ToInt32(detail.GlassCabinet),
                                Hanger       = Convert.ToInt32(detail.Hanger),
                                Hose15       = Convert.ToInt32(detail.Hose15),
                                Nozzle15     = Convert.ToInt32(detail.Nozzle15),
                                Hose25       = Convert.ToInt32(detail.Hose25),
                                Nozzle25     = Convert.ToInt32(detail.Nozzle25),
                                SpecialTools = Convert.ToInt32(detail.SpecialTools),


                                InspectedBy = detail.InspectedBy,
                                ReviewedBy  = detail.ReviewedBy,
                                NotedBy     = detail.NotedBy,

                                LocationFireHydrantId = detail.LocationFireHydrantId,


                                CreatedAt           = DateTime.Now.Date,
                                UpdatedAt           = DateTime.Now,
                                FireHydrantHeaderId = headerId,
                                Remarks             = detail.Remarks
                            };

                            _context.Add(_detail);
                        }
                        else
                        {
                            d.GlassCabinet = Convert.ToInt32(detail.GlassCabinet);
                            d.Hanger       = Convert.ToInt32(detail.Hanger);
                            d.Hose15       = Convert.ToInt32(detail.Hose15);
                            d.Nozzle15     = Convert.ToInt32(detail.Nozzle15);
                            d.Hose25       = Convert.ToInt32(detail.Hose25);
                            d.Nozzle25     = Convert.ToInt32(detail.Nozzle25);
                            d.SpecialTools = Convert.ToInt32(detail.SpecialTools);


                            d.InspectedBy = detail.InspectedBy;
                            d.Remarks     = detail.Remarks;
                            d.NotedBy     = detail.NotedBy;

                            d.LocationFireHydrantId = detail.LocationFireHydrantId;



                            d.UpdatedAt           = DateTime.Now;
                            d.UpdatedBy           = User.Identity.GetUserName();
                            d.FireHydrantHeaderId = headerId;
                            d.ReviewedBy          = detail.ReviewedBy;

                            _context.Update(d);
                        }
                        _context.SaveChanges();
                    }
                }



                _context.SaveChanges();
                status = "success";
            }
            catch (Exception ex)
            {
                status  = "failed";
                message = ex.InnerException.Message;
            }



            var model = new
            {
                status
                ,
                message
                ,
                ReferenceId = headerId
            };

            return(Json(model));
        }