コード例 #1
0
        public ActionResult Edit(SkipTransferFormModel model)
        {
            if (ModelState.IsValid)
            {
                SkipTransfer editedTransfer = _cdb.SkipTransfers.Find(model.ID);
                editedTransfer.IsValid           = true;
                editedTransfer.Status            = 3;
                editedTransfer.LasEditDateTime   = DateTime.Now;
                editedTransfer.OperatorName      = User.Identity.Name;
                _cdb.Entry(editedTransfer).State = EntityState.Modified;

                var transfer = new SkipTransfer();
                transfer.InheritedFrom     = model.ID;
                transfer.ID                = "S" + model.EquipID + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                transfer.LiftingID         = model.LiftingID;
                transfer.LasEditDateTime   = DateTime.Now;
                transfer.TransferTimeStamp = model.TransferTimeStamp;
                transfer.EquipID           = model.EquipID;
                transfer.SkipWeight        = model.SkipWeight;
                transfer.OperatorName      = User.Identity.Name;
                transfer.IsValid           = false;
                transfer.Status            = 2;

                _cdb.SkipTransfers.Add(transfer);
                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }

            @ViewBag.Title = "Редактирование данных скиповых подъемов";
            return(View("Edit", model));
        }
コード例 #2
0
        public ActionResult SaveChanges(WagonTransfer model)
        {
            if (ModelState.IsValid)
            {
                WagonTransfer transfer = _cdb.WagonTransfers.Find(model.ID);
                transfer.IsValid           = true;
                transfer.Status            = 3;
                transfer.LasEditDateTime   = DateTime.Now;
                transfer.OperatorName      = User.Identity.Name;
                _cdb.Entry(transfer).State = EntityState.Modified;
                _cdb.SaveChanges();

                model.LasEditDateTime = DateTime.Now;
                model.IsValid         = false;
                model.Status          = 2;
                model.OperatorName    = User.Identity.Name;
                model.InheritedFrom   = model.ID;
                model.ID = "W" + model.EquipID + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                _cdb.WagonTransfers.Add(model);
                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }
            GetDestinationsItemsAndScalesToVeiwBag();

            @ViewBag.Title = "Редактирование данных вагонных весов";
            return(View("Edit", model));
        }
コード例 #3
0
        public ActionResult Edit(VehiTransfer model)
        {
            if (ModelState.IsValid)
            {
                VehiTransfer transfer = _cdb.VehiTransfers.Find(model.ID);
                if (transfer == null)
                {
                    transfer = _cdb.VehiTransfers.Find(model.ID);
                }
                transfer.IsValid           = true;
                transfer.Status            = 3;
                transfer.LasEditDateTime   = DateTime.Now;
                transfer.OperatorName      = User.Identity.Name;
                _cdb.Entry(transfer).State = EntityState.Modified;
                _cdb.SaveChanges();

                model.InheritedFrom   = model.ID;
                model.ID              = "V" + model.EquipID + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                model.OperatorName    = User.Identity.Name;
                model.LasEditDateTime = DateTime.Now;
                model.IsValid         = false;
                model.Status          = 2;
                _cdb.VehiTransfers.Add(model);
                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }

            @ViewBag.Title = "Редактирование данных автомобильных весов";
            return(View("Edit", model));
        }
コード例 #4
0
        public ActionResult Add(WagonAnalysis model, string lotName)
        {
            if (ModelState.IsValid)
            {
                model.LasEditDateTime = DateTime.Now;
                model.IsValid         = true;
                model.OperatorName    = User.Identity.Name;
                //cdb.WagonAnalyzes.Add(model);

                List <WagonTransfer> transfers = new List <WagonTransfer>();
                transfers = _cdb.WagonTransfers.Where(x => x.LotName == lotName).ToList();
                transfers = _cdb.WagonTransfers.Where(x => x.LotName == lotName).ToList();

                foreach (var t in transfers)
                {
                    t.Analysis          = model;
                    _cdb.Entry(t).State = EntityState.Modified;
                }

                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }

            @ViewBag.LotName = lotName;

            @ViewBag.Title = "Добавление анализа для вагонных весов";
            return(View("Add", model));
        }
コード例 #5
0
        public ActionResult EditConfirmed(MiningAnalysis model)
        {
            if (ModelState.IsValid)
            {
                MiningAnalysis analysis = _cdb.MiningAnalyzes.Find(model.ID);
                analysis.IsValid           = false;
                analysis.LasEditDateTime   = DateTime.Now;
                analysis.OperatorName      = User.Identity.Name;
                _cdb.Entry(analysis).State = EntityState.Modified;

                model.LasEditDateTime = DateTime.Now;
                model.IsValid         = true;
                model.OperatorName    = User.Identity.Name;
                model.InheritedFrom   = analysis.ID;
                _cdb.MiningAnalyzes.Add(model);

                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }

            model.Location = EquipmentProvider.GetUserLocations(_cdb, User.Identity).Where(x => x.ID == model.LocationID).FirstOrDefault();
            @ViewBag.Title = "Редактирование анализа по добыче";
            return(View("Edit", model));
        }
コード例 #6
0
        public ActionResult Edit(RockUtilTransfer model)
        {
            if (!((model.LotQuantity != null) && ((float)model.LotQuantity > 0)))
            {
                ModelState.AddModelError("LotQuantity", "Некорректный вес - должен быть больше 0");
            }
            if (ModelState.IsValid)
            {
                RockUtilTransfer transfer = _cdb.RockUtilTransfers.Find(model.ID);
                transfer.IsValid           = true;
                transfer.Status            = 3;
                transfer.LasEditDateTime   = DateTime.Now;
                transfer.OperatorName      = User.Identity.Name;
                _cdb.Entry(transfer).State = EntityState.Modified;
                _cdb.SaveChanges();

                model.InheritedFrom = transfer.ID;
                model.ID            = "R" + model.EquipID + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                model.OperatorName  = User.Identity.Name;
                string name = Request.UserHostName;
                model.LasEditDateTime = DateTime.Now;
                model.IsValid         = false;
                model.Status          = 2;
                _cdb.RockUtilTransfers.Add(model);
                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }

            @ViewBag.Title = "Редактирование данных утилизации породы";
            return(View("Edit", model));
        }
コード例 #7
0
        public ActionResult WagonScalesEdit(WagonScale model)
        {
            if (String.IsNullOrEmpty(model.Name))
            {
                ModelState.AddModelError("Name", "Введите наименование - не может быть пустым");
            }
            if (String.IsNullOrEmpty(model.NameEng))
            {
                ModelState.AddModelError("NameEng", "Введите наименование - не может быть пустым");
            }
            if (String.IsNullOrEmpty(model.NameKZ))
            {
                ModelState.AddModelError("NameKZ", "Введите наименование - не может быть пустым");
            }
            if (ModelState.IsValid)
            {
                WagonScale wagonScale = _cdb.WagonScales.Find(model.ID);

                wagonScale.Name              = model.Name;
                wagonScale.NameEng           = model.NameEng;
                wagonScale.NameKZ            = model.NameKZ;
                _cdb.Entry(wagonScale).State = EntityState.Modified;
                _cdb.SaveChanges();

                return(RedirectToAction("WagonScalesIndex"));
            }

            @ViewBag.Title = "Редактирование вагонных весов";
            return(View("WagonScalesEdit", model));
        }
コード例 #8
0
        public ActionResult Edit(WarehouseMeasure model)
        {
            if (model.TotalMeasured <= 0)
            {
                ModelState.AddModelError("TotalMeasured", "Количество на складе должно быть больше 0");
            }
            if (model.MeasureDate > System.DateTime.Today)
            {
                ModelState.AddModelError("MeasureDate", "Неправильная дата - замер не может быть произведен в будущем");
            }
            if (ModelState.IsValid)
            {
                WarehouseMeasure measure = _cdb.WarehouseMeasures.Find(model.ID);
                measure.TotalMeasured     = model.TotalMeasured;
                measure.Comment           = model.Comment;
                measure.OperatorName      = User.Identity.Name;
                measure.LasEditDateTime   = System.DateTime.Now;
                _cdb.Entry(measure).State = EntityState.Modified;
                _cdb.SaveChanges();

                return(RedirectToAction("Index"));
            }

            @ViewBag.Title = "Редактирование данных маркшейдерского замера";
            return(View("Edit", model));
        }
コード例 #9
0
        public ActionResult Add(BeltAnalysis model, string alltransfers)
        {
            if (ModelState.IsValid)
            {
                //Get the list of transfers to add analysis
                string[]            transfersArray = alltransfers.Split(',');
                List <BeltTransfer> transfers      = new List <BeltTransfer>();

                foreach (var t in transfersArray)
                {
                    if (t != "")
                    {
                        try
                        {
                            transfers.Add(_cdb.InternalTransfers.Where(x => x.ID == t).FirstOrDefault());
                        }
                        catch
                        {
                        }
                    }
                }

                //Bind model
                model.LasEditDateTime = DateTime.Now;
                model.IsValid         = true;
                model.OperatorName    = User.Identity.Name;

                foreach (var t in transfers)
                {
                    if (t.Analysis != null)
                    {
                        BeltAnalysis analisys = new BeltAnalysis();
                        analisys                   = _cdb.BeltAnalyzes.Where(x => x.ID == t.AnalysisID).FirstOrDefault();
                        analisys.IsValid           = false;
                        _cdb.Entry(analisys).State = EntityState.Modified;
                    }

                    t.Analysis          = model;
                    _cdb.Entry(t).State = EntityState.Modified;
                }

                try
                {
                    _cdb.SaveChanges();
                }
                catch
                (Exception)
                { }
                return(RedirectToAction("Index"));
            }

            @ViewBag.alltransfers = alltransfers;
            @ViewBag.Title        = "Добавление анализа для конвейерных весов";
            return(View("Add", model));
        }
コード例 #10
0
        public ActionResult AddEditUser(string userLogin, string userDomain, string[] roles)
        {
            AddEditUserViewModel model;
            var ctsRoles = roles?.Select(r => _cdb.CtsRole.Find(r)) ?? _cdb.CtsRole;
            var user     = _cdb.CtsUser.Find(userLogin, userDomain);

            if (user == null)
            {
                model = new AddEditUserViewModel(userLogin, userDomain, ctsRoles.ToList());
            }
            else
            {
                _cdb.Entry(user).Collection(x => x.CtsRoles).Load();
                model = new AddEditUserViewModel(user, ctsRoles.ToList());
            }

            model.AllRoles   = roles == null;
            model.ReturnView = HttpContext.Request.UrlReferrer?.Segments.Last();
            return(View(model));
        }
コード例 #11
0
        public static ICollection <CtsRole> GetUserRolesFromDb(IIdentity user)
        {
            var cdb       = new CtsDbContext();
            var userLogin = user.Name.Split(new char[] { '\\' }).Last();
            var domain    = user.Name.Split(new char[] { '\\' }).First();


            if (!(Cacher.Instance.TryRead(domain + userLogin + "Roles") is CtsUser ctsUser))
            {
                ctsUser = cdb.CtsUser.Where(x => x.Login == userLogin).FirstOrDefault(x => x.Domain == domain);
                if (ctsUser != null)
                {
                    cdb.Entry(ctsUser).Collection(x => x.CtsRoles).Load();
                    Cacher.Instance.Write(domain + userLogin + "Roles", ctsUser);
                }
                else
                {
                    ctsUser = new CtsUser();
                }
            }
            return(ctsUser.CtsRoles);
        }
コード例 #12
0
        public static void ManageWeights()
        {
            var stringForLogger = new StringBuilder();

            try
            {
                CtsDbContext centralDB = new CtsDbContext();
                var          skips     = centralDB.Skips.ToList();

                foreach (var s in skips)
                {
                    var skipWeight = centralDB.SkipWeights.Where(x => x.SkipID == s.ID)
                                     .Where(d => d.ValidFrom <= System.DateTime.Now).OrderByDescending(m => m.ValidFrom).FirstOrDefault();
                    if (skipWeight != null)
                    {
                        if (s.Weight != skipWeight.Weight)
                        {
                            s.Weight = skipWeight.Weight;
                            centralDB.Entry(s).State = EntityState.Modified;
                            stringForLogger.Append("SkipID ");
                            stringForLogger.Append(s.ID);
                            stringForLogger.Append(" = ");
                            stringForLogger.Append(s.Weight);
                            stringForLogger.Append("; ");
                        }
                    }
                }

                centralDB.SaveChanges();
                stringForLogger.Insert(0, "Weight changed for ");
                _logger.Trace(stringForLogger.ToString());
            }
            catch (Exception ex)
            {
                _logger.Error("Unsuccess with SkipWeightHandler");
                _logger.Error(ex.ToString());
            }
        }