Exemplo n.º 1
0
        public IActionResult New(Package package, string ClientName, bool IsEnglish, bool IsClientSelected, bool OnlyAdminNotification)
        {
            if (!ModelState.IsValid)
            {
                NewPackageViewModel vm = new NewPackageViewModel
                {
                    IsClientSelected      = IsClientSelected,
                    Package               = package,
                    OnlyAdminNotification = OnlyAdminNotification,
                    ClientName            = ClientName,
                    IsEnglish             = IsEnglish
                };
                return(View(vm));
            }
            var currentUserIdClaim = HttpContext.User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).First();

            //The creator is the current user
            package.CreatorUserId = Convert.ToInt32(currentUserIdClaim.Value);
            _packagesRepo.Save(package);
            //Handling notification
            Func <Attorney, bool> filterNotifications = attorney
                                                        => !OnlyAdminNotification || attorney.User.IsAdmin == OnlyAdminNotification;
            var    emails = _attorneysRepo.Attorneys.Where(filterNotifications).Select(a => a.Email);
            string msg    = $"El usuario {HttpContext.User.Identity.Name} ha creado el paquete '{package.Name}' para el cliente {ClientName} " +
                            $"por un monto de honorarios acordados de ${package.Amount}.\n**Este es un mensaje autogenerado por el sistema, favor no responder**";

            _mailSender.SendMail(emails, "Creación de paquete", msg);
            TempData["added"] = true;
            return(RedirectToAction(nameof(New)));
        }
Exemplo n.º 2
0
        public IActionResult New()
        {
            ViewBag.AddedPackage = TempData["added"];
            NewPackageViewModel vm = new NewPackageViewModel
            {
                Package = new Package(),
                OnlyAdminNotification = true,
                IsEnglish             = false,
                IsClientSelected      = false
            };

            return(View(vm));
        }
Exemplo n.º 3
0
        // GET: Packages/Create
        public async Task <ActionResult> Create(int?OrderID)
        {
            if (OrderID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewBag.OrderID = OrderID;
            List <PackageProvider> delivers = await db.PackageProviders.Where(d => d.IsActive == 1).ToListAsync();

            NewPackageViewModel packageproviderVM = new NewPackageViewModel
            {
                AllPackageDelivers = delivers,
                SerialNumber       = "",
                OrderID            = OrderID ?? 0,
            };

            return(View(packageproviderVM));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Create([Bind(Include = "SelectedDeliverID,SerialNumber,MoneySpend,MoneyReceived,OrderID")] NewPackageViewModel package)
        {
            if (ModelState.IsValid)
            {
                if (Session["CurrentUserID"] == null)
                {
                    RedirectToAction("Login", "Home");
                }
                int CurrentUserID = (int)Session["CurrentUserID"];

                Package newPackage = new Package
                {
                    SerialNumber = package.SerialNumber,
                    ProviderID   = package.SelectedDeliverID,
                    OrderID      = package.OrderID,
                    UserID       = CurrentUserID
                };

                db.Packages.Add(newPackage);
                await db.SaveChangesAsync();
            }

            return(RedirectToAction("ProcessOrder", "Orders", new { id = package.OrderID }));
        }