Example #1
0
        public static string GetAssetAssignment(RestCommand command, int assetAssignmentsID)
        {
            AssetAssignment assetAssignment = AssetAssignments.GetAssetAssignment(command.LoginUser, assetAssignmentsID);

            if (assetAssignment.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(assetAssignment.GetXml("AssetAssignment", true));
        }
Example #2
0
        public static string AddAssetAssignment(RestCommand command, int assetID)
        {
            Asset asset = Assets.GetAsset(command.LoginUser, assetID);

            if (asset == null || asset.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            if (asset.Location == "3")
            {
                throw new RestException(HttpStatusCode.Forbidden, "Junkyard assets cannot be assigned. Please move it to the Warehouse before assigning it.");
            }

            AssetHistory     assetHistory     = new AssetHistory(command.LoginUser);
            AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem();

            assetHistoryItem.FullReadFromXml(command.Data, true);

            ValidateAssignment(command.LoginUser, assetHistoryItem);

            DateTime now = DateTime.UtcNow;

            assetHistoryItem.AssetID            = assetID;
            assetHistoryItem.OrganizationID     = command.LoginUser.OrganizationID;
            assetHistoryItem.ActionTime         = now;
            assetHistoryItem.ShippedFrom        = command.LoginUser.OrganizationID;
            assetHistoryItem.ShippedFromRefType = (int)ReferenceType.Organizations;
            assetHistoryItem.DateCreated        = now;
            assetHistoryItem.Actor        = command.LoginUser.UserID;
            assetHistoryItem.DateModified = now;
            assetHistoryItem.ModifierID   = command.LoginUser.UserID;
            assetHistory.Save();

            AssetAssignments assetAssignments = new AssetAssignments(command.LoginUser);
            AssetAssignment  assetAssignment  = assetAssignments.AddNewAssetAssignment();

            assetAssignment.HistoryID = assetHistoryItem.HistoryID;
            assetAssignments.Save();

            asset.Location   = "1";
            asset.AssignedTo = assetHistoryItem.ShippedTo;
            asset.Collection.Save();

            return(AssetAssignmentsView.GetAssetAssignmentsViewItem(command.LoginUser, assetAssignment.AssetAssignmentsID).GetXml("AssetAssignment", true));
        }
        public ActionResult UploadFile()
        {
            ExcelHelper excelHelp = new ExcelHelper();
            List <AssetAssignmentUploadModel> assignments = new List <AssetAssignmentUploadModel>();
            BulkUpload             currentUpload          = new Common.BulkUpload();
            BulkUploadProcess      bulkProcess            = new BulkUploadProcess();
            AssetProcess           assetProcess           = new AssetProcess();
            EmployeeProcess        employeeProcess        = new EmployeeProcess();
            Employee               sender        = new Employee();
            ConfigurationProcess   configProcess = new ConfigurationProcess();
            FastEmailConfiguration emailConfig   = configProcess.GetEmailConfiguration();
            AssignmentProcess      assignProcess = new AssignmentProcess();

            StringBuilder uploadLog = new StringBuilder();

            string filename         = string.Empty;
            string completeFileName = string.Empty;

            //This is for the logging
            bulkProcess.UserID     = User.Identity.Name.ToInteger();
            configProcess.UserID   = User.Identity.Name.ToInteger();
            employeeProcess.UserID = User.Identity.Name.ToInteger();
            assetProcess.UserID    = User.Identity.Name.ToInteger();
            assignProcess.UserID   = User.Identity.Name.ToInteger();

            try
            {
                #region Get Request Files
                foreach (string upload in Request.Files)
                {
                    if (!(Request.Files[upload] != null && Request.Files[upload].ContentLength > 0))
                    {
                        continue;
                    }
                    string path = HttpContext.Server.MapPath("\\App_Data\\BulkUploads");
                    filename = Path.GetFileName(Request.Files[upload].FileName);

                    //check the filename and ensure its an xlsx file
                    if (String.Compare(filename.Substring(filename.Length - 4), "xlsx", true) != 0)
                    {
                        throw new Exception("Invalid file extension.");
                    }

                    //add the current time as unique indicator
                    filename = DateTime.Now.ToFileTime().ToString() + "_" + filename;

                    // If Upload folder is not yet existing, this code will create that directory.
                    if (!System.IO.Directory.Exists(path))
                    {
                        System.IO.Directory.CreateDirectory(path);
                    }
                    completeFileName = Path.Combine(path, filename);
                    Request.Files[upload].SaveAs(completeFileName);
                }
                #endregion

                BulkUpload newFile = new BulkUpload()
                {
                    EmployeeID   = User.Identity.Name.ToInteger(),
                    FilePath     = filename,
                    TotalRecords = 0,
                    TotalInserts = 0,
                    RequestDate  = DateTime.Now,
                    Type         = FASTConstant.BULKIPLOAD_TYPE_ASSIGNMENT
                };

                if (bulkProcess.Add(newFile) == FASTConstant.RETURN_VAL_SUCCESS)
                {
                    //get the current upload
                    currentUpload = bulkProcess.GetCurrentUpload(newFile.FilePath, newFile.EmployeeID);
                }

                if (currentUpload != null)
                {
                    #region Process the excel file
                    //Success! Lets process the file.
                    System.Data.DataTable assignmentTable = new DataTable();

                    assignmentTable = excelHelp.GetExcelDataTable(completeFileName, "SELECT * FROM [AssetAssignment$]");

                    if (assignmentTable == null)
                    {
                        throw new Exception("The upload file contains null data.");
                    }

                    assignments = assignmentTable.ToList <Models.AssetAssignmentUploadModel>();
                    sender      = employeeProcess.GetEmployeeByID(currentUpload.EmployeeID);

                    if (assignments.Count > 0)
                    {
                        int totalInserts = 0;
                        currentUpload.TotalRecords = assignments.Count;

                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_INPROGRESS);

                        foreach (AssetAssignmentUploadModel assign in assignments)
                        {
                            //Get the Fix Asset to be added
                            Common.vwFixAssetList newAssignedAsset = assetProcess.GetFixAssetByAssetTag(assign.AssetTag);

                            AssetAssignment tempAssignment = new AssetAssignment()
                            {
                                EmployeeID         = assign.EmployeeID,
                                AssignmentStatusID = FASTConstant.ASSIGNMENT_STATUS_WT_ACCEPTANCE,
                                DateAssigned       = DateTime.Now,
                                FixAssetID         = newAssignedAsset.FixAssetID
                            };

                            if (String.Compare(newAssignedAsset.SerialNumber, assign.SerialNumber, true) == 0)
                            {
                                //totalInserts++;
                                //Try Assigning the asset to the Employee


                                //Add delay to allow sending of email
                                System.Threading.Thread.Sleep(2000);
                                uploadLog.AppendLine(String.Format("<p>{0} : {1} assigned to {2}.</p>",
                                                                   FASTConstant.SUCCESSFUL, assign.AssetTag, assign.EmployeeID.ToString()));
                            }
                            else
                            {
                                uploadLog.AppendLine(String.Format("<p>{0} : {1} not assigned to {2}. Serial Number Mismatch.</p>",
                                                                   FASTConstant.FAILURE, assign.AssetTag, assign.EmployeeID.ToString()));
                            }
                        }

                        currentUpload.TotalInserts = totalInserts;
                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_DONE);


                        //Send email to the requestor
                        FastEmail email = new FastEmail();
                        email.Receipients = new List <string>()
                        {
                            sender.EmailAddress
                        };
                        email.Subject  = FASTConstant.EMAIL_SIMPLE_SUBJECT.Replace("[XXX]", "Fix Asset Bulk Upload Result");
                        email.HTMLBody = FASTProcess.Helper.EmailHelper.GenerateHTMLBody(FASTProcess.Helper.EmailHelper.EmailType.BULK_UPLOAD);

                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_RECEIPIENT_NAME, sender.FirstName + " " + sender.LastName);
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_INFO, bulkProcess.GenerateUploadinformationHTML(currentUpload));
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_LOG, uploadLog.ToString());
                        email.HTMLBody = email.HTMLBody.Replace(FASTConstant.EMAIL_BULKUPLOAD_SUMMARY, bulkProcess.GenerateSummaryinformationHTML(currentUpload));

                        SMTPEmail emailSender = new SMTPEmail(emailConfig, email);
                        emailSender.SendEmail();
                    }
                    else
                    {
                        bulkProcess.UpdateProcessingStep(currentUpload, FASTConstant.BULKUPLOAD_STATUS_DONE);
                    }
                    #endregion
                }

                TempData["Result"]       = "SUCCESSFUL";
                TempData["Source"]       = "File Upload";
                TempData["ExtraMessage"] = "An email will be sent to you containing the results of the upload process.";
                TempData["Action"]       = "Index";
                TempData["Controller"]   = "FixAsset";

                return(View("~/Views/Shared/Result.cshtml"));
            }
            catch (Exception ex)
            {
                TempData["Result"]       = "FAILURE";
                TempData["Source"]       = "Fix Asset Bulk Upload";
                TempData["ExtraMessage"] = ex.Message;
                return(View("~/Views/Shared/Result.cshtml"));
            }
        }
        public string AssignAsset(int assetID, string data)
        {
            AssignAssetSave info;

            try
            {
                info = Newtonsoft.Json.JsonConvert.DeserializeObject <AssignAssetSave>(data);
            }
            catch (Exception e)
            {
                return("error");
            }

            LoginUser loginUser = TSAuthentication.GetLoginUser();
            Asset     o         = Assets.GetAsset(loginUser, assetID);

            //Location 1=assigned (shipped), 2=warehouse, 3=junkyard
            o.Location   = "1";
            o.AssignedTo = info.RefID;
            DateTime now = DateTime.UtcNow;

            o.DateModified = now;
            o.ModifierID   = loginUser.UserID;
            o.Collection.Save();

            AssetHistory     assetHistory     = new AssetHistory(loginUser);
            AssetHistoryItem assetHistoryItem = assetHistory.AddNewAssetHistoryItem();

            assetHistoryItem.AssetID            = assetID;
            assetHistoryItem.OrganizationID     = loginUser.OrganizationID;
            assetHistoryItem.ActionTime         = DateTime.UtcNow;
            assetHistoryItem.ActionDescription  = "Asset Shipped on " + info.DateShipped.Month.ToString() + "/" + info.DateShipped.Day.ToString() + "/" + info.DateShipped.Year.ToString();
            assetHistoryItem.ShippedFrom        = loginUser.OrganizationID;
            assetHistoryItem.ShippedFromRefType = (int)ReferenceType.Organizations;
            assetHistoryItem.ShippedTo          = info.RefID;
            assetHistoryItem.TrackingNumber     = info.TrackingNumber;
            assetHistoryItem.ShippingMethod     = info.ShippingMethod;
            assetHistoryItem.ReferenceNum       = info.ReferenceNumber;
            assetHistoryItem.Comments           = info.Comments;

            assetHistoryItem.DateCreated  = now;
            assetHistoryItem.Actor        = loginUser.UserID;
            assetHistoryItem.RefType      = info.RefType;
            assetHistoryItem.DateModified = now;
            assetHistoryItem.ModifierID   = loginUser.UserID;

            assetHistory.Save();

            AssetAssignments assetAssignments = new AssetAssignments(loginUser);
            AssetAssignment  assetAssignment  = assetAssignments.AddNewAssetAssignment();

            assetAssignment.HistoryID = assetHistoryItem.HistoryID;

            assetAssignments.Save();

            string description = String.Format("Assigned asset to {0}.", info.AssigneeName);

            ActionLogs.AddActionLog(loginUser, ActionLogType.Update, ReferenceType.Assets, assetID, description);

            AssetsView assetsView = new AssetsView(loginUser);

            assetsView.LoadByAssetID(assetID);

            StringBuilder productVersionNumberDisplayName = new StringBuilder();

            if (!string.IsNullOrEmpty(assetsView[0].ProductVersionNumber))
            {
                productVersionNumberDisplayName.Append(" - " + assetsView[0].ProductVersionNumber);
            }

            StringBuilder serialNumberDisplayValue = new StringBuilder();

            if (string.IsNullOrEmpty(assetsView[0].SerialNumber))
            {
                serialNumberDisplayValue.Append("Empty");
            }
            else
            {
                serialNumberDisplayValue.Append(assetsView[0].SerialNumber);
            }

            StringBuilder warrantyExpirationDisplayValue = new StringBuilder();

            if (assetsView[0].WarrantyExpiration == null)
            {
                warrantyExpirationDisplayValue.Append("Empty");
            }
            else
            {
                warrantyExpirationDisplayValue.Append(((DateTime)assetsView[0].WarrantyExpiration).ToString(GetDateFormatNormal()));
            }

            return(string.Format(@"<div class='list-group-item'>
                            <a href='#' id='{0}' class='assetLink'><h4 class='list-group-item-heading'>{1}</h4></a>
                            <div class='row'>
                                <div class='col-xs-8'>
                                    <p class='list-group-item-text'>{2}{3}</p>
                                </div>
                            </div>
                            <div class='row'>
                                <div class='col-xs-8'>
                                    <p class='list-group-item-text'>SN: {4} - Warr. Exp.: {5}</p>
                                </div>
                            </div>
                            </div>"

                                 , assetID
                                 , assetsView[0].DisplayName
                                 , assetsView[0].ProductName
                                 , productVersionNumberDisplayName
                                 , serialNumberDisplayValue
                                 , warrantyExpirationDisplayValue));
        }
Example #5
0
        public static Dictionary <string, int> GetNextStatus(ActionType action, int assetID, int assignmentID = 0)
        {
            BO.AssetProcess      assetProcess  = new BO.AssetProcess();
            BO.AssignmentProcess assignProcess = new BO.AssignmentProcess();

            Dictionary <string, int> result = new Dictionary <string, int>();

            vwFixAssetList  asset      = assetProcess.GetAssetByID(assetID);
            AssetAssignment assignment = new AssetAssignment();

            if (assignmentID > 0)
            {
                assignment = assignProcess.GetAssignmentbyID(assignmentID);
            }

            //FA - FixAsset Status;
            //AA - Current Assignment Status ( for transafer, this is for the requestor)
            //NAA - Next Assignment Status ( only for transfer, this is for the receipient)

            switch (action)
            {
            case ActionType.ASSET_NEW:
                result.Clear();
                result.Add("FA", Constants.ASSET_STATUS_FORASSIGNMENT);
                return(result);

            case ActionType.ASSET_TRANSFER:
                result.Clear();
                result.Add("FA", Constants.ASSET_STATUS_FORTRANSFER);
                result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_APPROVAL);
                return(result);

            case ActionType.ASSET_TRANSFER_WOAPPROVAL:
            case ActionType.ASSET_TRANSFER_APPROVED:
                result.Clear();
                if (asset.AssetStatusID == Constants.ASSET_STATUS_WITH_MIS)
                {
                    result.Add("FA", Constants.ASSET_STATUS_ASSIGNED);
                    result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_ACCEPTANCE);
                }
                else
                {
                    result.Add("FA", Constants.ASSET_STATUS_ASSIGNED);
                    result.Add("AA", Constants.ASSIGNMENT_STATUS_RELEASED);
                    result.Add("NAA", Constants.ASSIGNMENT_STATUS_WT_ACCEPTANCE);
                }
                return(result);

            case ActionType.ASSET_TRANSFER_DENIED:
            case ActionType.ASSET_RELEASE_DENIED:
                result.Clear();
                result.Add("FA", Constants.ASSET_STATUS_ASSIGNED);
                result.Add("AA", Constants.ASSIGNMENT_STATUS_ACCEPTED);
                return(result);

            case ActionType.ASSET_RELEASE:
                result.Clear();
                result.Add("FA", Constants.ASSET_STATUS_FORRELEASE);
                result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_APPROVAL);
                return(result);

            case ActionType.ASSET_RELEASE_WOAPPROVAL:
            case ActionType.ASSET_RELEASE_APPROVED:
                result.Clear();
                result.Add("FA", Constants.ASSET_STATUS_RELEASED);
                result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_ACCEPTANCE);
                return(result);

            case ActionType.ASSIGNMENT_MIS:
                result.Clear();
                result.Add("FA", Constants.ASSET_STATUS_WITH_MIS);
                result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_ACCEPTANCE);
                return(result);

            case ActionType.ASSIGNMENT_EMPLOYEE:
                result.Clear();
                result.Add("FA", Constants.ASSET_STATUS_ASSIGNED);
                result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_ACCEPTANCE);
                return(result);

            case ActionType.ASSET_RELEASE_ACCEPTED:
            case ActionType.ASSIGNMENT_ACCEPTED:
                result.Clear();
                result.Add("FA", asset.AssetStatusID);
                result.Add("AA", Constants.ASSIGNMENT_STATUS_ACCEPTED);
                return(result);

            case ActionType.ASSET_RELEASE_REJECTED:
                result.Clear();
                result.Add("FA", Constants.ASSIGNMENT_STATUS_RELEASED);
                result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_APPROVAL);
                return(result);

            case ActionType.ASSIGNMENT_REJECTED:
                result.Clear();
                switch (asset.AssetStatusID)
                {
                case Constants.ASSET_STATUS_WITH_MIS:
                    result.Add("FA", Constants.ASSET_STATUS_FORRELEASE);
                    result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_APPROVAL);
                    break;

                case Constants.ASSET_STATUS_ASSIGNED:
                    result.Add("FA", Constants.ASSET_STATUS_FORRELEASE);
                    result.Add("AA", Constants.ASSIGNMENT_STATUS_WT_APPROVAL);
                    break;

                case Constants.ASSET_STATUS_FORRELEASE:
                    result.Add("FA", asset.AssetStatusID);
                    result.Add("AA", assignment.AssignmentStatusID);
                    break;
                }
                return(result);
            }

            return(result);
        }
Example #6
0
 public Task SaveAssetAssignment(AssetAssignment assignment, string token) =>
 PostAsync(assignment, token, "assets", "assignments");