コード例 #1
0
        public ActionResult Create(RequestCrane rc)
        {
            if (rc.Request.ApproverEmployeeId == 0)
            {
                ViewBag.ErrorMessage = "Веберите руководителя, который подпишет заявку!";
                return(View(rc));
            }

            try
            {
                rc.Request.Status      = 0;
                rc.Request.UserLogin   = User.Identity.Name;
                rc.Request.UserFio     = AccountManager.GetUserDisplayName(User.Identity.Name);
                rc.Request.PublishDate = DateTime.Now;
                rc.Request.IsDeleted   = false;

                if (rc.Request.CustomerId == 0)
                {
                    rc.Request.CustomerId = null;
                }

                if (Utils.AccountManager.IsApprover(User.Identity.Name).Item2)
                {
                    rc.Request.SendToSpecTrans = true;
                    rc.Request.Status          = 1;
                    rc.Request.ApproveDate     = DateTime.Now;
                    rc.Request.ApproverLogin   = User.Identity.Name;
                    rc.Request.ApproverFio     = Utils.AccountManager.GetUserDisplayName(User.Identity.Name);

                    var re = new RequestEvent {
                        Status = 1, EventDate = DateTime.Now
                    };
                    rc.Request.RequestEvents.Add(re);
                }

                _db.RequestCranes.Add(rc);
                _db.SaveChanges();

                return(View("Published", rc.Request.RequestId));
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        //TODO: Попытка удалить запись, у которой ExpDate истек
                    }
                }

                ViewBag.ErrMessage     = "Ошибка при создании записи";
                ViewBag.BackController = "Home";
                return(View("Error"));
            }
        }
コード例 #2
0
        public ActionResult SignAll(int id)
        {
            if (!_db.RequestApprovers.Any(a => a.EmployeeId == id) && !User.IsInRole("LAN\\TR_Admins"))
            {
                ViewBag.BackController = "Home";
                return(View("Denied"));
            }

            try
            {
                var rqsts = _db.Requests.Where(rq => (rq.ApproverEmployeeId == id && (rq.Status == 0 || rq.Status == 3))).ToList();
                foreach (var rqst in rqsts)
                {
                    rqst.ApproveDate   = DateTime.Now;
                    rqst.ApproverLogin = User.Identity.Name;
                    rqst.ApproverFio   = AccountManager.GetUserDisplayName(User.Identity.Name);
                    rqst.Status        = 1;

                    RequestEvent re = new RequestEvent();
                    re.Status    = 1;
                    re.Message   = String.Empty;
                    re.EventDate = DateTime.Now;

                    rqst.RequestEvents.Add(re);

                    if (rqst.RequestInternational != null)
                    {
                        var tel = AccountManager.GetUserPhoneNumber(rqst.UserLogin);
                        new EmailSender().Send(rqst.RequestId, rqst.UserFio, tel, rqst.RequestInternational.Way);
                    }
                    else
                    {
                        rqst.SendToSpecTrans = true;
                    }
                }
                _db.SaveChanges();
                ViewBag.Message = "Заявки подписаны!";
            }
            catch
            {
                ViewBag.Message = "Ошибка при подписи заявок, заявки не подписаны!";
            }
            return(View("Signed"));
        }
コード例 #3
0
        public ActionResult Create(RequestPassenger rp)
        {
            if (ModelState.IsValid)
            {
                if (rp.Request.ApproverEmployeeId == 0)
                {
                    ViewBag.ErrorMessage = "Веберите руководителя, который подпишет заявку!";
                    return(View(rp));
                }

                if ((rp.Request.DepartmentGroupId ?? 0) == 0)
                {
                    ViewBag.ErrorMessage = "Веберите структурное подразделение!";
                    return(View(rp));
                }

                if ((rp.Request.DirectionId ?? 0) == 0)
                {
                    ViewBag.ErrorMessage = "Веберите направление перевозки!";
                    return(View(rp));
                }

                if ((rp.Request.AgreementPurposeId ?? 0) == 0)
                {
                    ViewBag.ErrorMessage = "Веберите цель перевозки!";
                    return(View(rp));
                }


                /* try
                 * {*/

                var customer = _db.v_RequestCustomers.FirstOrDefault(
                    x => x.DirectionId == rp.Request.DirectionId && x.PurposeId == rp.Request.AgreementPurposeId);

                if (customer == null)
                {
                    ViewBag.ErrorMessage = "Не найден заказчик по направлению и цели перевозки.";
                    return(View(rp));
                }

                rp.Request.CustomerId = customer.CustomerId;

                rp.Request.Status      = 0;
                rp.Request.UserLogin   = User.Identity.Name;
                rp.Request.UserFio     = AccountManager.GetUserDisplayName(User.Identity.Name);
                rp.Request.PublishDate = DateTime.Now;
                rp.Request.IsDeleted   = false;

                if (Utils.AccountManager.IsApprover(User.Identity.Name).Item2)
                {
                    rp.Request.SendToSpecTrans = true;
                    rp.Request.Status          = 1;
                    rp.Request.ApproveDate     = DateTime.Now;
                    rp.Request.ApproverLogin   = User.Identity.Name;
                    rp.Request.ApproverFio     = Utils.AccountManager.GetUserDisplayName(User.Identity.Name);

                    var re = new RequestEvent {
                        Status = 1, EventDate = DateTime.Now
                    };
                    rp.Request.RequestEvents.Add(re);
                }

                if (rp.Request.CustomerId == 0)
                {
                    rp.Request.CustomerId = null;
                }

                if (rp.Request.RequestTypeId == 0)
                {
                    rp.Request.RequestTypeId = null;
                }

                _db.RequestPassengers.Add(rp);
                _db.SaveChanges();
                return(View("Published", rp.Request.RequestId));

                /*}
                 * catch
                 * {
                 *  ViewBag.ErrMessage = "Ошибка при создании записи";
                 *  ViewBag.BackController = "Passenger";
                 *  return View("Error");
                 * }*/
            }
            return(View());
        }
コード例 #4
0
        public ActionResult Create(RequestFreight rf, IEnumerable <HttpPostedFileBase> files)
        {
            if (rf.Request.ApproverEmployeeId == 0)
            {
                ViewBag.ErrorMessage = "Веберите руководителя, который подпишет заявку!";
                return(View(rf));
            }


            if ((rf.Request.DepartmentGroupId ?? 0) == 0)
            {
                ViewBag.ErrorMessage = "Веберите структурное подразделение!";
                return(View(rf));
            }

            if ((rf.Request.DirectionId ?? 0) == 0)
            {
                ViewBag.ErrorMessage = "Веберите направление перевозки!";
                return(View(rf));
            }

            if ((rf.Request.AgreementPurposeId ?? 0) == 0)
            {
                ViewBag.ErrorMessage = "Веберите цель перевозки!";
                return(View(rf));
            }


            try
            {
                rf.Request.Status      = 0;
                rf.Request.UserLogin   = User.Identity.Name;
                rf.Request.UserFio     = AccountManager.GetUserDisplayName(User.Identity.Name);
                rf.Request.PublishDate = DateTime.Now;
                rf.Request.IsDeleted   = false;


                var customer = _db.v_RequestCustomers.FirstOrDefault(
                    x => x.DirectionId == rf.Request.DirectionId && x.PurposeId == rf.Request.AgreementPurposeId);

                if (customer == null)
                {
                    ViewBag.ErrorMessage = "Не найден заказчик по направлению и цели перевозки.";
                    return(View(rf));
                }

                rf.Request.CustomerId = customer.CustomerId;


                if (rf.Request.RequestTypeId == 0)
                {
                    rf.Request.RequestTypeId = null;
                }

                if (Utils.AccountManager.IsApprover(User.Identity.Name).Item2)
                {
                    rf.Request.SendToSpecTrans = true;
                    rf.Request.Status          = 1;
                    rf.Request.ApproveDate     = DateTime.Now;
                    rf.Request.ApproverLogin   = User.Identity.Name;
                    rf.Request.ApproverFio     = Utils.AccountManager.GetUserDisplayName(User.Identity.Name);

                    RequestEvent re = new RequestEvent();
                    re.Status    = 1;
                    re.EventDate = DateTime.Now;
                    rf.Request.RequestEvents.Add(re);
                }

                //Файлы
                if (files != null)
                {
                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            RequestAttachment attFile = new RequestAttachment();
                            attFile.Name = file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1);

                            int    fl = file.ContentLength;
                            byte[] fc = new byte[fl];

                            file.InputStream.Read(fc, 0, fl);

                            attFile.Cont = fc;

                            rf.Request.RequestAttachments.Add(attFile);
                        }
                    }
                }

                _db.RequestFreights.Add(rf);
                _db.SaveChanges();

                return(View("Published", rf.Request.RequestId));
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName,
                                               validationError.ErrorMessage);
                        //TODO: Попытка удалить запись, у которой ExpDate истек
                    }
                }

                ViewBag.ErrMessage     = "Ошибка при создании записи";
                ViewBag.BackController = "Home";
                return(View("Error"));
            }
        }
コード例 #5
0
        /// <summary>
        /// Is current user has permissions to approve transport requests
        /// </summary>
        /// <param name="identity"></param>
        /// <returns>Tuple where Item1 - EmloyeeId, Item2 - is this user approver </returns>
        public static Tuple <int, bool> IsApprover(string identity)
        {
            var _db = new transportEntities();

            if (String.IsNullOrEmpty(identity))
            {
                return(new Tuple <int, bool>(10, true));
            }

            var      login    = Login(identity);
            Employee employee = _db.Employees.SingleOrDefault(e => e.Login == login);

            if (employee == null)
            {
                var context = new PrincipalContext(ContextType.Domain, "lan.naftan.by");
                if (identity.Substring(0, 7).ToLower() == "polymir") //If user from Polymir than MAGIC
                {
                    //парсить кусок логина на предмет табельного номера
                    string tabN = identity.Substring(9, identity.Length - 9);
                    int    n    = 0;
                    for (int i = 0; i < tabN.Length; i++)
                    {
                        if (tabN.Substring(i, 1) != "0")
                        {
                            n = i;
                            break;
                        }
                    }
                    tabN     = tabN.Substring(n, tabN.Length - n); //предполагаемый табельный номер
                    employee = _db.Employees.SingleOrDefault(e => e.EmployeeNumber == tabN);
                }
                else //User from Naftan, do search in AD
                {
                    string sIdMan = String.Empty;
                    int    idMan  = 0;
                    using (context)
                    {
                        var principal = UserPrincipal.FindByIdentity(context, identity);
                        sIdMan = principal.EmployeeId;
                    }
                    Int32.TryParse(sIdMan, out idMan);
                    employee = _db.Employees.SingleOrDefault(e => e.id_men == idMan);

                    if (employee == null)
                    //Если полимировец с логином из домена LAN
                    {
                        //парсить кусок логина на предмет табельного номера
                        string tabN = identity.Substring(5, identity.Length - 5);
                        int    n    = 0;
                        for (int i = 0; i < tabN.Length; i++)
                        {
                            if (tabN.Substring(i, 1) != "0")
                            {
                                n = i;
                                break;
                            }
                        }
                        tabN     = tabN.Substring(n, tabN.Length - n); //предполагаемый табельный номер
                        employee = _db.Employees.SingleOrDefault(e => e.EmployeeNumber == tabN);
                    }
                }

                if (employee != null)
                {
                    employee.Login = login;
                    _db.SaveChanges();
                }
            }

            if (employee == null)
            {
                return(Tuple.Create(0, false));
            }

            bool isApprover = _db.RequestApprovers.Any(ap => ap.EmployeeId == employee.EmployeeId);

            return(Tuple.Create(employee.EmployeeId, isApprover));
        }
コード例 #6
0
        public ActionResult Create(RequestInternational rf, IEnumerable <HttpPostedFileBase> files)
        {
            if (rf.Request.ApproverEmployeeId == 0)
            {
                ViewBag.ErrorMessage = "Веберите руководителя, который подпишет заявку!";
                return(View(rf));
            }

            if ((rf.Request.DepartmentGroupId ?? 0) == 0)
            {
                ViewBag.ErrorMessage = "Веберите структурное подразделение!";
                return(View(rf));
            }

            if ((rf.Request.DirectionId ?? 0) == 0)
            {
                ViewBag.ErrorMessage = "Веберите направление перевозки!";
                return(View(rf));
            }


            var Way = "Внутри Республики Беларусь";


            if (rf.Way == Way)
            {
                rf.DepartureCustoms = "";
                rf.ReturnCustoms    = "";
                rf.Code             = "";
            }
            else
            {
                rf.Request.AgreementPurposeId = null;
            }


            if (rf.Way == Way && (rf.Request.AgreementPurposeId ?? 0) == 0)
            {
                ViewBag.ErrorMessage = "Веберите цель перевозки!";
                return(View(rf));
            }


            if (rf.Way != Way && String.IsNullOrEmpty(rf.DepartureCustoms))
            {
                ViewBag.ErrorMessage = "Таможня отправления обязательно для заполнения";
                return(View(rf));
            }
            if (rf.Way != Way && String.IsNullOrEmpty(rf.ReturnCustoms))
            {
                ViewBag.ErrorMessage = "Таможня назначения обязательно для заполнения";
                return(View(rf));
            }
            if (rf.Way != Way && String.IsNullOrEmpty(rf.PackageListNumber))
            {
                ViewBag.ErrorMessage = "№ упаковочного листа обязательно для заполнения";
                return(View(rf));
            }
            if (rf.Way != Way && String.IsNullOrEmpty(rf.Code))
            {
                ViewBag.ErrorMessage = "Код ТНВЭД обязательно для заполнения";
                return(View(rf));
            }

            try
            {
                rf.Request.Status      = 0;
                rf.Request.UserLogin   = User.Identity.Name;
                rf.Request.UserFio     = AccountManager.GetUserDisplayName(User.Identity.Name);
                rf.Request.PublishDate = DateTime.Now;
                rf.Request.IsDeleted   = false;

                if (rf.Request.CustomerId == 0)
                {
                    rf.Request.CustomerId = null;
                }

                if (rf.Request.RequestTypeId == 0)
                {
                    rf.Request.RequestTypeId = null;
                }

                var isApproved = false;

                if (Utils.AccountManager.IsApprover(User.Identity.Name).Item2)
                {
                    isApproved               = true;
                    rf.Request.Status        = 1;
                    rf.Request.ApproveDate   = DateTime.Now;
                    rf.Request.ApproverLogin = User.Identity.Name;
                    rf.Request.ApproverFio   = AccountManager.GetUserDisplayName(User.Identity.Name);

                    rf.Request.RequestEvents.Add(new RequestEvent {
                        Status = 1, EventDate = DateTime.Now
                    });
                }

                //Файлы
                if (files != null)
                {
                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            RequestAttachment attFile = new RequestAttachment();
                            attFile.Name = file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1);

                            int    fl = file.ContentLength;
                            byte[] fc = new byte[fl];

                            file.InputStream.Read(fc, 0, fl);

                            attFile.Cont = fc;

                            rf.Request.RequestAttachments.Add(attFile);
                        }
                    }
                }

                // throw new Exception("Debug");


                _db.RequestInternationals.Add(rf);
                _db.SaveChanges();

                if (isApproved)
                {
                    //var tel = AccountManager.GetUserPhoneNumber(rf.Request.UserLogin);
                    new EmailSender().Send(rf.RequestId, rf.Request.Responsible, "", rf.Way);
                }

                return(View("Published", rf.Request.RequestId));
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName,
                                               validationError.ErrorMessage);
                        //TODO: Попытка удалить запись, у которой ExpDate истек
                    }
                }

                throw (dbEx);

                ViewBag.ErrMessage     = "Ошибка при создании записи:";
                ViewBag.BackController = "Home";
                return(View("Error"));
            }
        }