コード例 #1
0
        public ActionResult ResetOrderStatus(int id)
        {
            try
            {
                GATE_MaterialRequest oldRequest = DB.GATE_MaterialRequest
                    .Include(x => x.MaterialAction)
                    .Include(x => x.Message)
                    .Include(x => x.Package)
                    .Include(x => x.Package.GenericMaterials)
                    .First(x => x.MaterialRequestId == id);
                oldRequest.OrderStatusId = OrderStatus.Cancelled;
                oldRequest.CancellationComment = "Order reset";

                GATE_MaterialRequest newRequest = new GATE_MaterialRequest
                {
                    OrderStatusId = OrderStatus.HelpDeskProductProposal,
                    ConcernedEmployeeId = oldRequest.ConcernedEmployeeId,
                    OrderedByEmployeeId = oldRequest.OrderedByEmployeeId,
                    PackageId = oldRequest.PackageId,
                    RequestDate = oldRequest.RequestDate,
                    ExpectedDate = oldRequest.ExpectedDate,
                    Comment = oldRequest.Comment,
                    AddressId = oldRequest.AddressId,
                    AmarisOfficeId = oldRequest.AmarisOfficeId,
                    CurrencyId = oldRequest.CurrencyId,
                    OrderTypeId = oldRequest.OrderTypeId,
                    TotalCost = oldRequest.TotalCost,
                    IsAutomated = oldRequest.IsAutomated,
                    MaterialAction = oldRequest.MaterialAction.ToList(),
                    Message = oldRequest.Message.ToList()
                };

                //cloning the old list using ToList()

                //Request the individual components (aparently this is necessary, although I am not sure why ...)
                Package thePackage = oldRequest.Package;
                foreach (var material in thePackage.GenericMaterials)
                {
                    GATE_ComponentRequest component = new GATE_ComponentRequest
                    {
                        MaterialId = material.GenericMaterialId,
                        IsSetup = !material.RequiresSetup,
                        IsDispatched = false,
                        MaterialRequestId = newRequest.MaterialRequestId,
                        StatusId = OrderStatus.HelpDeskProductProposal
                    };

                    DB.GATE_ComponentRequest.Add(component);
                }

                //Adding new Material Actions and Messages
                foreach (MaterialAction action in newRequest.MaterialAction)
                {
                    DB.MaterialActions.Add(action);
                }

                foreach (Message message in newRequest.Message)
                {
                    DB.Messages.Add(message);
                }

                DB.GATE_MaterialRequest.Add(newRequest);
                DB.SaveChanges();
                DB.GATE_MaterialRequest.UpdatePermissions(newRequest.MaterialRequestId);

                return new HttpStatusCodeResult(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message);
            }
        }
コード例 #2
0
ファイル: MailHelper.cs プロジェクト: dangokc/CodeSnippets
        private void EmailSender_OrderValidated(GATE_MaterialRequest materialRequest, int orderNumber)
        {
            string linkToOrder = _controller.Url.Action("Index", "OrderDetails", new { id = orderNumber }, _controller.Request.Url.Scheme);

            _controllerDb.SendMail("purchasingDptNotification", new
            {
                orderNumber = orderNumber,
                LinkToOrder = linkToOrder
            }, userId: _senderId, applicationName: _appName);
        }
コード例 #3
0
ファイル: MailHelper.cs プロジェクト: dangokc/CodeSnippets
        /// <summary>
        /// This function acts as a distributor. It choses the right email to send in relation of the status or last action of the material request. 
        /// So, on the process methods this needs to be called whenever an email is needed.
        /// </summary>
        /// <param name="materialRequest">Material Request object</param>
        public void SendAlertMails(GATE_MaterialRequest materialRequest)
        {
            Employee concernedEmployee = materialRequest.ConcernedEmployee;
            Employee orderedEmployee = materialRequest.OrderedByEmployee;
            Employee concernedEmployeeManager = materialRequest.ConcernedEmployee.Manager;
            Employee lom = (materialRequest.Office != null ? materialRequest.Office.LocalOfficeManager.FirstOrDefault() : null);

            string concernedEmployeeName = concernedEmployee.Name;
            string concernedEmployeeEmail = concernedEmployee.Email ?? string.Empty;
            string orderedByEmployeeEmail = (orderedEmployee != null ? orderedEmployee.Email : string.Empty );
            int orderNumber = materialRequest.MaterialRequestId;
            string managerName = concernedEmployeeManager.Name;
            string managerEmail = concernedEmployeeManager != null ? (concernedEmployeeManager.Email ?? string.Empty) : string.Empty;
            string lomEmail = (lom != null ? lom.Email : string.Empty);

            string directorEmails = string.Empty;
            if (concernedEmployee.WorkingForCompany != null)
            {
               directorEmails = String.Join(", ", concernedEmployee.WorkingForCompany.CompanyDirectors.ToDictionary(dir => dir.Email).Keys);
            }

            string concernedScopes = string.Empty;
            List<Employee_Scope> concernedScopesList = concernedEmployee.Employee_Scope.ToList();
            if (concernedScopesList.Any())
            {
                foreach (Employee_Scope aScope in concernedScopesList)
                {
                    concernedScopes += "Company: " + aScope.Company.CompanyCodeName + ", Function: " + aScope.Employee_Function.Label + System.Environment.NewLine;
                }
            }
            else
            {
                concernedScopes = "No scope defined for this employee yet.";
            }

            //Find out wich kind of email from the app Amaris.Mails should be called depending on the status of the material Request. Modifiers can be aplied.
            switch (materialRequest.OrderStatusId)
            {
                case OrderStatus.HelpDeskProductProposal:
                    EmailSender_OrderCreated(materialRequest, concernedEmployeeEmail, orderNumber, managerEmail, lomEmail, directorEmails, concernedEmployeeName, managerName, concernedScopes);
                    break;
                case OrderStatus.ProductDelivery:
                    EmailSender_OrderValidated(materialRequest, orderNumber);
                    break;
                case OrderStatus.ProductSetup:
                    EmailSender_OrderReadyForSetUp(materialRequest, orderNumber, concernedEmployeeName);
                    break;
                case OrderStatus.ProductDispatch:
                    break;
                case OrderStatus.Complete:
                    EmailSender_OrderReadyForDispatch(orderNumber, concernedEmployeeName, managerEmail, lomEmail);
                    break;
                case OrderStatus.Cancelled:
                    if (materialRequest.MaterialAction.Last().ActionId == (int)GActions.PurchasingDptCancelPrice ||
                        materialRequest.MaterialAction.Last().ActionId == (int)GActions.DirectorCancelPrice ||
                        materialRequest.MaterialAction.Last().ActionId == (int)GActions.ManagerCancelPrice)

                        EmailSender_OrderSuspended(materialRequest, concernedEmployeeEmail, orderedByEmployeeEmail, orderNumber, managerEmail);
                    else
                        EmailSender_OrderCancellation(materialRequest, orderedByEmployeeEmail, orderNumber, managerEmail, concernedEmployeeEmail);
                    break;
            }
        }
コード例 #4
0
ファイル: MailHelper.cs プロジェクト: dangokc/CodeSnippets
        private void EmailSender_OrderSuspended(GATE_MaterialRequest materialRequest, string employeeEmail, string requesterEmail, int orderNumber, string managerEmail)
        {
            var helpDeskEmail = materialRequest.MaterialAction.Last(x => x.ActionId == (int)GActions.ExpertProposesProd).Employee.Email ?? "*****@*****.**";
            var directorEmail = materialRequest.MaterialAction.Any(x => x.ActionId == (int)GActions.DirectorValidate
                                                                 || x.ActionId == (int)GActions.DirectorCancelPrice
                                                                 || x.ActionId == (int)GActions.DirectorCancelRelevancy) ?
                                                                                        materialRequest.MaterialAction.Last(x => x.ActionId == (int)GActions.DirectorValidate
                                                                                                                || x.ActionId == (int)GActions.DirectorCancelPrice
                                                                                                                || x.ActionId == (int)GActions.DirectorCancelRelevancy).Employee.Email
                                                                                        : "*****@*****.**";
            var purchasingOfficerEmail = materialRequest.MaterialAction.Last(x => x.ActionId == (int)GActions.PurchasingDptCancelPrice).Employee.Email ?? "*****@*****.**";
            var orderRequestedDate = materialRequest.RequestDate.ToShortDateString();
            var orderExpectedDate = (materialRequest.ExpectedDate.HasValue ? materialRequest.ExpectedDate.Value.Date.ToString() : "None");
            var lastSuspenderName = materialRequest.MaterialAction.Last().Employee.Name ?? "";
            var lastSuspendingDate = materialRequest.MaterialAction.Last().Employee.Email ?? "*****@*****.**";

            var pendingOrderUrl = _controller.Url.Action("Index", "OrderDetails", new { id = orderNumber }, _controller.Request.Url.Scheme);

            _controllerDb.SendMail("OrderSuspended", new
            {
                orderNumber = orderNumber.ToString(CultureInfo.InvariantCulture),
                helpDeskOfficerEmail = helpDeskEmail,
                employeeEmail = employeeEmail,
                requesterEmail = requesterEmail,
                managerEmail = managerEmail,
                directorEmail = directorEmail,
                purchasingOfficerEmail = purchasingOfficerEmail,
                orderRequestedDate = orderRequestedDate,
                orderExpectedDate = orderExpectedDate,
                lastSuspenderName = lastSuspenderName,
                lastSuspendingDate = lastSuspendingDate,
                pendingOrderURL = pendingOrderUrl
            }, userId: _senderId, applicationName: _appName);
        }
コード例 #5
0
ファイル: MailHelper.cs プロジェクト: dangokc/CodeSnippets
        private void EmailSender_OrderReadyForSetUp(GATE_MaterialRequest materialRequest, int orderNumber, string concernedEmployeeName)
        {
            IEnumerable<GATE_ComponentRequest> components = materialRequest.ComponentRequests.Where(y => y.IsSetup == false);
            List<string> productSetupRequiredList = new List<string>();

            foreach (GATE_ComponentRequest productRequired in components)
            {
                productSetupRequiredList.Add(productRequired.GenericMaterial.Label);
            }

            var pendingSetupUrl = _controller.Url.Action("Index", "OrderDetails", new { id = orderNumber }, _controller.Request.Url.Scheme);

            _controllerDb.SendMail("SetupNeeded", new
            {
                employeeName = concernedEmployeeName,
                orderNumber = orderNumber,
                productSetupRequiredList = string.Join("<br/> - ", productSetupRequiredList),
                linkToOrder =  "<a href=\"" + pendingSetupUrl + "\"> here!</a>"
            }, userId: _senderId, applicationName: _appName);
        }
コード例 #6
0
ファイル: MailHelper.cs プロジェクト: dangokc/CodeSnippets
        private void EmailSender_OrderCreated(GATE_MaterialRequest materialRequest, string employeeEmail, int orderNumber, string managerEmail, string lomEmail, string directorEmails, string employeeName, string managerName, string employeeFunctions)
        {
            string amarisGateHomeUrl = _controller.Url.Action("Index", "OrderDetails", new { id = orderNumber }, _controller.Request.Url.Scheme);
            string materialNamesStr = "Empty";
            if (materialRequest.Package != null)
            {
                List<string> materialNamesList = materialRequest.Package.GenericMaterials.ToDictionary(mat => mat.GenericMaterialId, mat => mat.Label).Values.ToList();
                materialNamesStr = String.Join(",", materialNamesList);
            }

            Company workingForComp = materialRequest.ConcernedEmployee.WorkingForCompany;
            Boolean isConsultant = materialRequest.ConcernedEmployee.EmployeeType.EmployeeTypeId == 2;
            if (isConsultant)
            {
                _controllerDb.SendMail("NewConsultantArrivalNotification", new
                {
                    managerName = managerName,
                    employeeName = employeeName,
                    employeeFunctions = employeeFunctions,
                    employeeWorkingFor = (workingForComp != null ? workingForComp.CompanyCodeName : "Working for no company."),
                    managerEmail = managerEmail,
                    directorEmail = directorEmails,
                    LOMEmail = lomEmail,
                    orderNumber = orderNumber
                }, userId: _senderId, applicationName: _appName);
            }
            else
            {
                _controllerDb.SendMail("NewStaffRequestFromDNA", new
                {
                    managerEmail = managerEmail,
                    LOMEmail = lomEmail,
                    directorEmail = directorEmails,
                    employeeHostedByCompany = (materialRequest.ConcernedEmployee.HostedByCompany != null ? materialRequest.ConcernedEmployee.HostedByCompany.CompanyCodeName : "No company is hosting the concerned employee yet"),
                    packageName = (materialRequest.Package != null ? materialRequest.Package.PackageName : "No package assigned"),
                    employeeEmail = employeeEmail,
                    employeeName = employeeName,
                    employeeFunctions = employeeFunctions,
                    MaterialList = materialNamesStr,
                    linkToOrder = amarisGateHomeUrl,
                    orderNumber = orderNumber
                }, userId: _senderId, applicationName: _appName);
            }
        }
コード例 #7
0
ファイル: MailHelper.cs プロジェクト: dangokc/CodeSnippets
        private void EmailSender_OrderCancellation(GATE_MaterialRequest materialRequest, string requesterEmail, int orderNumber, string managerEmail, string employeeEmail)
        {
            var directorEmail = materialRequest.MaterialAction.Any(x => x.ActionId == (int)GActions.DirectorValidate
                                                                 || x.ActionId == (int)GActions.DirectorCancelPrice
                                                                 || x.ActionId == (int)GActions.DirectorCancelRelevancy) ?
                                                                                        materialRequest.MaterialAction.Last(x => x.ActionId == (int)GActions.DirectorValidate
                                                                                                                || x.ActionId == (int)GActions.DirectorCancelPrice
                                                                                                                || x.ActionId == (int)GActions.DirectorCancelRelevancy).Employee.Email
                                                                                        : "*****@*****.**";

            var purchasingOfficerEmail = materialRequest.MaterialAction.Any(x => x.ActionId == (int)GActions.SentForOrder
                                                                          || x.ActionId == (int)GActions.PurchasingDptCancelPrice
                                                                          || x.ActionId == (int)GActions.PurchasingDptCancelRelevancy) ?
                                                                                        materialRequest.MaterialAction.Last(x => x.ActionId == (int)GActions.SentForOrder
                                                                                                                || x.ActionId == (int)GActions.PurchasingDptCancelPrice
                                                                                                                || x.ActionId == (int)GActions.PurchasingDptCancelRelevancy).Employee.Email
                                                                                        : "*****@*****.**";

            var orderRequestedDate = materialRequest.RequestDate.ToShortDateString();
            var cancellerName = materialRequest.MaterialAction.Last().Employee.Name;
            var cancellationDate = materialRequest.MaterialAction.Last().DetailDate;
            var cancellationComments = materialRequest.CancellationComment ?? "No comments";

            _controllerDb.SendMail("OrderCancellation", new
            {
                requesterEmail = requesterEmail,
                employeeEmail = employeeEmail,
                managerEmail = managerEmail,
                directorEmail = directorEmail,
                purchasingOfficerEmail = purchasingOfficerEmail,
                orderNumber = orderNumber.ToString(CultureInfo.InvariantCulture),
                orderRequestedDate = orderRequestedDate,
                cancellerName = cancellerName,
                cancellationDate = cancellationDate,
                cancellationComments = cancellationComments
            }, userId: _senderId, applicationName: _appName);
        }
コード例 #8
0
        public void DnaNewOrder(int newEmployeeId)
        {
            //1. Function + Company found(Host By)
            //2. Function only found
            //3. Default package
            Employee newEmployee = DB.Employees.Find(newEmployeeId);

            if (newEmployee == null)
            {
                Response.Write("No employees with that Id were found");
                return;
            }

            GATE_MaterialRequest newRequest = new GATE_MaterialRequest
            {
                AmarisOfficeId = (newEmployee.OfficeExtension != null ? newEmployee.OfficeExtension.OfficeId : -1),
                ConcernedEmployeeId = newEmployeeId,
                IsAutomated = true,
                RequestDate = DateTime.Today,
                OrderedByEmployeeId = newEmployee.ManagerId.GetValueOrDefault(),
                OrderStatusId = OrderStatus.HelpDeskProductProposal,
                OrderTypeId = 1
            };

            newRequest.Office = DB.Offices.Find(newRequest.AmarisOfficeId);

            //The ids of all the functions the new employee has (1 employee can have several functions)
            //Get functions by using scope
            var employeeFunctions = DB.Employee_Scope
                .Where(sco => sco.EmployeeId == newEmployeeId)
                .Select(sco => sco.FunctionId);

            //List of ids of all the functions each package has
            var packageFunctions =
                from package in DB.Packages
                select new { packageId = package.PackageId, packageFunctionIds = (from aFunction in package.Functions select aFunction.FunctionId) };

            //Find if there is a package for the specific functions of the new Employee
            //Match employee functions with package functions
            List<int> packageIds = new List<int>();
            List<int> functionIds;
            foreach (var tuple in packageFunctions)
            {
                functionIds = (List<int>)tuple.packageFunctionIds;
                //Find if functionIds contains all items inside employeeFunctions
                //http://stackoverflow.com/questions/1520642/does-net-have-a-way-to-check-if-list-a-contains-all-items-in-list-b
                if (!employeeFunctions.Except(functionIds).Any() && employeeFunctions.Any())
                {
                    packageIds.Add(tuple.packageId);
                }
            }

            //There is a package with all the functions of the new Employee. We enter case 1 or 2
            if (!packageIds.IsNullOrEmpty())
            {
                //case 1: Function + Company
                List<Package> possibleTargets = new List<Package>();

                //There is a package more specific for the employee
                if (!possibleTargets.IsNullOrEmpty())
                {
                    //case 1
                    newRequest.PackageId = possibleTargets.First().PackageId;
                }
                else
                {
                    //case 2
                    newRequest.PackageId = packageIds.First();
                }

                //Request the individual components (aparently this is necessary, although I am not sure why ...)
                Package thePackage = DB.Packages.Find(newRequest.PackageId);

                foreach (var material in thePackage.GenericMaterials)
                {
                    GATE_ComponentRequest component = new GATE_ComponentRequest
                    {
                        MaterialId = material.GenericMaterialId,
                        IsSetup = !material.RequiresSetup,
                        IsDispatched = false,
                        MaterialRequestId = newRequest.MaterialRequestId,
                        StatusId = OrderStatus.HelpDeskProductProposal
                    };

                    GATE_MaterialSuggestion newSuggestion = new GATE_MaterialSuggestion
                    {
                        InStock = false,
                        IsNotStandardProduct = false,
                        Label = string.Empty,
                        CurrencyId = "EUR"
                    };

                    DB.GATE_MaterialSuggestion.Add(newSuggestion);

                    DB.GATE_ComponentRequest.Add(component);
                    component.CurrentSuggestion = newSuggestion;
                }
            }
            //No package has the functions our Employee has, so we skip directly to order the default package
            else
            {
                //case 3
                newRequest.PackageId = null;
            }

            MaterialAction firstAction = new MaterialAction
            {
                ActionId = 26,
                EmployeeId = newEmployee.ManagerId ?? newEmployeeId,
                DetailDate = DateTime.Now,
                Comment  = "Order automatically created via external service"
            };
            newRequest.MaterialAction.Add(firstAction);
            DB.MaterialActions.Add(firstAction);

            //set default Address
            Address defaultAddress = new Address
            {
                Complement = string.Empty,
                CreatedDate = DateTime.Now
            };
            DB.Addresses.Add(defaultAddress);
            newRequest.AddressId = defaultAddress.ID;

            DB.GATE_MaterialRequest.Add(newRequest);

            DB.SaveChanges();
            DB.GATE_MaterialRequest.UpdatePermissions(newRequest.MaterialRequestId);

            MailMan.SendAlertMails(newRequest);

            Response.Write("Request Sucessfull");
        }