コード例 #1
0
ファイル: ItemsController.cs プロジェクト: KrisMalapit/SEM
        public async Task <IActionResult> Create(ItemViewModel item)
        {
            if (item.DatePurchased == null)
            {
                item.Warranty = 0;
            }
            if (ModelState.IsValid)
            {
                //int companyAccess = Convert.ToInt32(User.Identity.GetCompanyAccess());//disabled 01032022
                int    companyAccess = item.CompanyId;
                string series        = "";
                string refno         = "";
                string st            = "";

                string series_code = "";

                if (companyAccess == 1)
                {
                    series_code = "ITEMSLPGC";
                    st          = "SLIT";
                }
                if (companyAccess == 2)
                {
                    series_code = "ITEMSCPC";
                    st          = "SCIT";
                }


                series = new NoSeriesController(_context).GetNoSeries(series_code);

                refno = st + series;



                item.Code = refno;
                Item _item = new Item {
                    Code = item.Code,

                    Name = item.Name,

                    SerialNo = item.SerialNo,

                    DatePurchased = item.DatePurchased,

                    Warranty = item.Warranty,

                    ItemStatus = item.ItemStatus,

                    Status = "Active",

                    EquipmentType = item.EquipmentType,

                    IsIn = 1,

                    Type = item.Type,

                    Capacity = item.Capacity
                };

                _context.Add(_item);
                await _context.SaveChangesAsync();


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


                ItemLog itemLog = new ItemLog
                {
                    ItemId      = item.Id,
                    OldStatus   = "",
                    NewStatus   = "New",
                    CreatedDate = DateTime.Now,
                    CreatedBy   = User.Identity.GetFullName(),
                    Description = "Item added to item maintenance"
                };
                _context.Add(itemLog);


                Log log = new Log
                {
                    Descriptions = "Create Item - " + item.Id,
                    Action       = "Create",
                    Status       = "success",
                    UserId       = User.Identity.GetUserName()
                };
                _context.Add(log);
                _context.SaveChanges();



                return(RedirectToAction(nameof(Index)));
            }
            return(View(item));
        }
コード例 #2
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));
        }
コード例 #3
0
        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));
        }
コード例 #4
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));
        }
コード例 #5
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));
        }