public async Task <Asset> SaveNewAssetAsync(Asset asset, AssetType type, Staff assignedToStaff, string assignedDate)
        {
            asset.TypeId = type.Id;
            await _context.Assets.AddAsync(asset);

            await _context.SaveChangesAsync();

            //todo: add validation for type and staff
            if (asset.Status == AssetStatus.Assigned)
            {
                var history = new AssetHistory
                {
                    AssignedDate = DateTime.Parse(assignedDate),
                    AssetId      = asset.Id,
                    StaffId      = assignedToStaff.Id
                };

                asset.LastAssignedDate = DateTime.Parse(assignedDate);

                await _context.AssetsHistory.AddAsync(history);

                await _context.SaveChangesAsync();
            }

            return(asset);
        }
Example #2
0
        public void Update(Asset asset)
        {
            repository.Update(asset);

            //Go first to define de text and then generates & return the QR Code image
            asset.QrCode = TxtQrCodeGenerator(asset.AssetID);

            repository.Update(asset);


            AssetHistory assetHistory = repositoryAssetHistory.GetLatestAssetHistoryOfAsset(asset.AssetID);

            if (assetHistory == null || asset.StatusID != assetHistory.StatusID)
            {
                assetHistory = new AssetHistory();

                //Not working
                assetHistory.AssetID  = asset.AssetID;
                assetHistory.StatusID = asset.StatusID;
                assetHistory.Datum    = DateTime.Now;
                assetHistory.NameUser = userManager.Users.FirstOrDefault().UserName.Replace("@portofantwerp.com", "");

                repositoryAssetHistory.Add(assetHistory);
            }
        }
Example #3
0
        public IActionResult Edit(long id, [Bind("AssetHistoryID, AssetID, StatusID, Datum, NameUser, Description")] AssetHistory assetHistory)
        {
            if (id != assetHistory.AssetHistoryID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    service.Update(assetHistory);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AssetHistoryExists(assetHistory.AssetHistoryID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Edit", "Asset", new { id = assetHistory.AssetID }));
            }
            return(RedirectToAction("Edit", "Asset", new { id = assetHistory.AssetID }));
        }
Example #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            AssetHistory assetHistory = db.AssetHistories.Find(id);

            db.AssetHistories.Remove(assetHistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #5
0
        public Tuple <long, AssetHistory, Asset> GetAssetHistoryWithSub(long assetHistoryID)
        {
            AssetHistory assetHistory = FindById(assetHistoryID);

            Asset asset = repositoryAsset.FindById(assetHistory.AssetID);

            return(new Tuple <long, AssetHistory, Asset>(assetHistoryID, assetHistory, asset));
        }
Example #6
0
        public IActionResult Create([Bind("AssetHistoryID,AssetID,StatusID,Datum,NameUser,Description")] AssetHistory assetHistory)
        {
            if (ModelState.IsValid)
            {
                service.Add(assetHistory);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(assetHistory));
        }
Example #7
0
 public ActionResult Edit([Bind(Include = "ID,Cash,Stock,Reits,ETF,Bond,Property,Loan,Debt,CPFOrdinary,CPFMedisave,CPFSpecial,Amount,RecordDate")] AssetHistory assetHistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(assetHistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(assetHistory));
 }
Example #8
0
        public static string GetAssetHistoryItem(RestCommand command, int historyID)
        {
            AssetHistoryItem assetHistoryItem = AssetHistory.GetAssetHistoryItem(command.LoginUser, historyID);

            if (assetHistoryItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(assetHistoryItem.GetXml("AssetHistoryItem", true));
        }
        public IHttpActionResult AddItem([FromBody] AssetHistory item)
        {
            if (item == default(AssetHistory))
            {
                return(BadRequest("Invalid request. No item could be found."));
            }

            var logic = new AssetManagerLogic();

            return(Ok(logic.AddItem(item)));
        }
Example #10
0
        // GET: AssetHistory/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AssetHistory assetHistory = db.AssetHistories.Find(id);

            if (assetHistory == null)
            {
                return(HttpNotFound());
            }
            return(View(assetHistory));
        }
Example #11
0
        public static string GetAssetHistory(RestCommand command)
        {
            AssetHistory assetHistory = new AssetHistory(command.LoginUser);

            assetHistory.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(assetHistory.GetXml("AssetHistory", "AssetHistoryItem", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
Example #12
0
        // GET: AssetHistory/Edit/
        public IActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AssetHistory assetHistory = service.FindById(id.Value);

            if (assetHistory == null)
            {
                return(NotFound());
            }

            return(View(assetHistory));
        }
Example #13
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));
        }
        /// <summary>
        /// Converts this instance of <see cref="AssetHistoryDTO"/> to an instance of <see cref="AssetHistory"/>.
        /// </summary>
        /// <param name="dto"><see cref="AssetHistoryDTO"/> to convert.</param>
        public static AssetHistory ToEntity(this AssetHistoryDTO dto)
        {
            if (dto == null)
            {
                return(null);
            }

            var entity = new AssetHistory();

            entity.ID               = dto.ID;
            entity.AssetID          = dto.AssetID;
            entity.ModifiedByUserID = dto.ModifiedByUserID;
            entity.ModifiedDate     = dto.ModifiedDate;
            entity.AuditDate        = dto.AuditDate;
            dto.OnEntity(entity);

            return(entity);
        }
        public async Task <string> GetCurrentAssignedStaff(Asset asset)
        {
            string staffName = null;


            AssetHistory history = await _context.AssetsHistory
                                   .Where(h => h.Asset == asset)
                                   .Include(h => h.Staff)
                                   .OrderByDescending(h => h.AssignedDate)
                                   .FirstOrDefaultAsync();

            if (history != null)
            {
                staffName = history.Staff.Name;
            }

            return(staffName);
        }
        /// <summary>
        /// Converts this instance of <see cref="AssetHistory"/> to an instance of <see cref="AssetHistoryDTO"/>.
        /// </summary>
        /// <param name="entity"><see cref="AssetHistory"/> to convert.</param>
        public static AssetHistoryDTO ToDTO(this AssetHistory entity)
        {
            if (entity == null)
            {
                return(null);
            }

            var dto = new AssetHistoryDTO();

            dto.ID               = entity.ID;
            dto.AssetID          = entity.AssetID;
            dto.ModifiedByUserID = entity.ModifiedByUserID;
            dto.ModifiedDate     = entity.ModifiedDate;
            dto.AuditDate        = entity.AuditDate;
            entity.OnDTO(dto);

            return(dto);
        }
        public static string CreateAsset(RestCommand command)
        {
            DateTime now    = DateTime.UtcNow;
            Assets   assets = new Assets(command.LoginUser);
            Asset    asset  = assets.AddNewAsset();

            asset.OrganizationID = command.Organization.OrganizationID;
            asset.FullReadFromXml(command.Data, true);
            if (asset.ProductID == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, "Product required");
            }
            // For consistency all assets are created in the warehouse.
            asset.Location = "2";
            // This is normally not necessary, but as the CreatorID is defined as a null field in this table it is needed.
            asset.CreatorID     = command.LoginUser.UserID;
            asset.NeedsIndexing = true;
            asset.DateCreated   = now;
            asset.DateModified  = now;
            asset.Collection.Save();
            asset.UpdateCustomFieldsFromXml(command.Data);

            string           description = String.Format("Asset {0} created via API.", GetAssetReference(asset));
            AssetHistory     history     = new AssetHistory(command.LoginUser);
            AssetHistoryItem historyItem = history.AddNewAssetHistoryItem();

            historyItem.OrganizationID    = command.Organization.OrganizationID;
            historyItem.Actor             = command.LoginUser.UserID;
            historyItem.AssetID           = asset.AssetID;
            historyItem.ActionTime        = DateTime.UtcNow;
            historyItem.ActionDescription = "Asset created via API.";
            historyItem.ShippedFrom       = 0;
            historyItem.ShippedTo         = 0;
            historyItem.TrackingNumber    = string.Empty;
            historyItem.ShippingMethod    = string.Empty;
            historyItem.ReferenceNum      = string.Empty;
            historyItem.Comments          = string.Empty;
            historyItem.DateCreated       = now;
            historyItem.DateModified      = now;

            history.Save();

            return(AssetsView.GetAssetsViewItem(command.LoginUser, asset.AssetID).GetXml("Asset", true));
        }
        public async Task <AssetHistory> Unassign(AssetHistory history)
        {
            var date = DateTime.Now;

            history.UnAssignedDate = date;
            _context.AssetsHistory.Update(history);

            Asset asset = await _context.Assets.FirstOrDefaultAsync(a => a.Id == history.Asset.Id);

            asset.Status = Enums.AssetStatus.NotAssigned;

            _context.Assets.Update(asset);

            await _context.SaveChangesAsync();

            _context.Dispose();

            return(history);
        }
        public async Task <AssetHistory> AssignAssetAsync(Asset asset, Staff staff)
        {
            var history = new AssetHistory
            {
                AssignedDate = DateTime.Now,
                AssetId      = asset.Id,
                StaffId      = staff.Id
            };

            await _context.AssetsHistory.AddAsync(history);

            asset.LastAssignedDate = DateTime.Now;
            _context.Assets.Update(asset);

            await _context.SaveChangesAsync();

            _context.Dispose();

            return(history);
        }
        public int JunkAsset(int assetID, string comments)
        {
            LoginUser loginUser = TSAuthentication.GetLoginUser();
            Asset     o         = Assets.GetAsset(loginUser, assetID);

            //Location 1=assigned (shipped), 2=warehouse, 3=junkyard
            o.Location   = "3";
            o.AssignedTo = null;
            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 assigned to Junkyard";
            assetHistoryItem.ShippedFrom        = -1;
            assetHistoryItem.ShippedFromRefType = -1;
            assetHistoryItem.ShippedTo          = -1;
            assetHistoryItem.RefType            = -1;
            assetHistoryItem.TrackingNumber     = string.Empty;
            assetHistoryItem.ShippingMethod     = string.Empty;
            assetHistoryItem.ReferenceNum       = string.Empty;
            assetHistoryItem.Comments           = comments;

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

            assetHistory.Save();

            ActionLogs.AddActionLog(loginUser, ActionLogType.Update, ReferenceType.Assets, assetID, "Junked asset.");

            return(assetID);
        }
Example #21
0
        internal void SaveCurrentSummary()
        {
            List<AssetSummary> result = CalcSummary();

            AssetHistory assetHistory = db.AssetHistories.OrderByDescending(i => i.RecordDate).FirstOrDefault();
            if (assetHistory == null || assetHistory.RecordDate.Date != DateTime.Now.Date)
            {
                // if no record of current data
                assetHistory = new AssetHistory();
                db.AssetHistories.Add(assetHistory);
            }
            else
            {
                db.Entry(assetHistory).State = EntityState.Modified;
            }

            // set values
            assetHistory.RecordDate = DateTime.Now;
            foreach (AssetSummary a in result)
            {
                if (a.Category== "Cash")
                {
                    assetHistory.Cash = a.Amount;
                }
                else if (a.Category == "Stock")
                {
                    assetHistory.Stock = a.Amount;
                }
                else if (a.Category == "Reits")
                {
                    assetHistory.Reits = a.Amount;
                }
                else if (a.Category == "Bond")
                {
                    assetHistory.Bond = a.Amount;
                }
            }

            db.SaveChanges();
        }
        public async Task <Asset> DiscardAssetAsync(Asset asset)
        {
            var discardedDate = DateTime.Now;

            asset.DiscardedDate = discardedDate;
            asset.Status        = AssetStatus.Discarded;
            _context.Assets.Update(asset);

            AssetHistory history = await _context.AssetsHistory.Where(a => a.Asset == asset).Where(a => a.UnAssignedDate == null).FirstOrDefaultAsync();

            if (history != null)
            {
                history.UnAssignedDate = discardedDate;
                _context.AssetsHistory.Update(history);
            }

            await _context.SaveChangesAsync();

            _context.Dispose();

            return(asset);
        }
Example #23
0
        public IHttpActionResult SendForApproval(int AssetRequestId, int LastModifiedBy)
        {
            string retMsg         = string.Empty;
            string AssetStatus    = "Awaiting Quotation Approval";
            long   RaiseRequestId = AssetRequestId;

            try
            {
                if (AssetRequestId > 0)
                {
                    var dbAssetStatusId = db.AssetStatus.Where(c => c.Name.ToUpper() == AssetStatus.ToUpper()).Select(x => x.Id).FirstOrDefault();

                    var assetRequest = db.AssetRequests.SingleOrDefault(x => x.Id == RaiseRequestId);
                    if (assetRequest != null)
                    {
                        assetRequest.AssetStatusId  = dbAssetStatusId;
                        assetRequest.LastModifiedOn = System.DateTime.Now;
                        assetRequest.LastModifiedBy = LastModifiedBy;
                        db.SaveChanges();
                        retMsg = "Updated";
                    }

                    AssetHistory assetHistory = new AssetHistory();
                    assetHistory.AssetRequestId   = AssetRequestId;
                    assetHistory.TargetStatusId   = dbAssetStatusId;
                    assetHistory.StatusChangedBy  = LastModifiedBy;
                    assetHistory.StatusModifiedOn = System.DateTime.Now;
                    assetHistory.Comments         = assetRequest.Comments;
                    db.AssetHistories.Add(assetHistory);
                    db.SaveChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(Ok(retMsg));
        }
        public IHttpActionResult UpdateItem([FromBody] AssetHistory item)
        {
            if (item.ID == default(int))
            {
                return(BadRequest("Invalid item specified."));
            }

            if (!DateTime.TryParse(item.CheckedOutDate.ToString(), out DateTime outParse) || item.CheckedOutDate.Year == 0001)
            {
                return(BadRequest("Invalid check out date specified."));
            }

            var logic = new AssetManagerLogic();

            try
            {
                return(Ok(logic.UpdateItem(item)));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public int SaveAsset(string data)
        {
            NewAssetSave info;

            try
            {
                info = Newtonsoft.Json.JsonConvert.DeserializeObject <NewAssetSave>(data);
            }
            catch (Exception e)
            {
                return(-1);
            }

            LoginUser loginUser = TSAuthentication.GetLoginUser();
            Assets    assets    = new Assets(loginUser);
            Asset     asset     = assets.AddNewAsset();

            asset.OrganizationID     = TSAuthentication.OrganizationID;
            asset.Name               = info.Name;
            asset.ProductID          = info.ProductID;
            asset.ProductVersionID   = info.ProductVersionID;
            asset.SerialNumber       = info.SerialNumber;
            asset.WarrantyExpiration = DataUtils.DateToUtc(TSAuthentication.GetLoginUser(), info.WarrantyExpiration);
            asset.Notes              = info.Notes;
            //Location 1=assigned (shipped), 2=warehouse, 3=junkyard
            asset.Location = "2";

            asset.DateCreated  = DateTime.UtcNow;
            asset.DateModified = DateTime.UtcNow;
            asset.CreatorID    = loginUser.UserID;
            asset.ModifierID   = loginUser.UserID;

            asset.Collection.Save();

            string description = String.Format("Created asset {0} ", GetAssetReference(asset));

            ActionLogs.AddActionLog(TSAuthentication.GetLoginUser(), ActionLogType.Insert, ReferenceType.Assets, asset.AssetID, description);

            foreach (CustomFieldSaveInfo field in info.Fields)
            {
                CustomValue customValue = CustomValues.GetValue(TSAuthentication.GetLoginUser(), field.CustomFieldID, asset.AssetID);
                if (field.Value == null)
                {
                    customValue.Value = "";
                }
                else
                {
                    if (customValue.FieldType == CustomFieldType.DateTime)
                    {
                        customValue.Value = ((DateTime)field.Value).ToString();
                        //DateTime dt;
                        //if (DateTime.TryParse(((string)field.Value), System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal, out dt))
                        //{
                        //    customValue.Value = dt.ToUniversalTime().ToString();
                        //}
                    }
                    else
                    {
                        customValue.Value = field.Value.ToString();
                    }
                }

                customValue.Collection.Save();
            }

            AssetHistory     history     = new AssetHistory(loginUser);
            AssetHistoryItem historyItem = history.AddNewAssetHistoryItem();

            historyItem.OrganizationID    = loginUser.OrganizationID;
            historyItem.Actor             = loginUser.UserID;
            historyItem.AssetID           = asset.AssetID;
            historyItem.ActionTime        = DateTime.UtcNow;
            historyItem.ActionDescription = "Asset created.";
            historyItem.ShippedFrom       = 0;
            historyItem.ShippedTo         = 0;
            historyItem.TrackingNumber    = string.Empty;
            historyItem.ShippingMethod    = string.Empty;
            historyItem.ReferenceNum      = string.Empty;
            historyItem.Comments          = string.Empty;

            history.Save();

            return(asset.AssetID);
        }
        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));
        }
        public int ReturnAsset(int assetID, string data)
        {
            AssignAssetSave info;

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

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

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

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

            AssetAssignmentsView assetAssignmentsView = new AssetAssignmentsView(loginUser);

            assetAssignmentsView.LoadByAssetID(assetID);

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

            assetHistoryItem.AssetID            = assetID;
            assetHistoryItem.OrganizationID     = loginUser.OrganizationID;
            assetHistoryItem.ActionTime         = DateTime.UtcNow;
            assetHistoryItem.ActionDescription  = "Item returned to warehouse on " + info.DateShipped.Month.ToString() + "/" + info.DateShipped.Day.ToString() + "/" + info.DateShipped.Year.ToString();
            assetHistoryItem.ShippedFrom        = assetAssignmentsView[0].ShippedTo;
            assetHistoryItem.ShippedFromRefType = assetAssignmentsView[0].RefType;
            assetHistoryItem.ShippedTo          = loginUser.OrganizationID;
            assetHistoryItem.RefType            = (int)ReferenceType.Organizations;
            assetHistoryItem.TrackingNumber     = info.TrackingNumber;
            assetHistoryItem.ShippingMethod     = info.ShippingMethod;
            assetHistoryItem.ReferenceNum       = info.ReferenceNumber;
            assetHistoryItem.Comments           = info.Comments;

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

            assetHistory.Save();

            AssetAssignments assetAssignments = new AssetAssignments(loginUser);

            foreach (AssetAssignmentsViewItem assetAssignmentViewItem in assetAssignmentsView)
            {
                assetAssignments.DeleteFromDB(assetAssignmentViewItem.AssetAssignmentsID);
            }

            ActionLogs.AddActionLog(loginUser, ActionLogType.Update, ReferenceType.Assets, assetID, "Returned asset.");

            return(assetID);
        }
Example #28
0
        // POST api/RaiseRequest
        public IHttpActionResult PostAssetQuoteApproval()
        {
            long   assetQuotationId, entityTypeId;
            int    loginId;
            string comments, status = string.Empty, PONumber = string.Empty, sdate = string.Empty;
            bool   isAwaitingNextApproval;
            long   dbMaxPONumber = 0;

            try
            {
                HttpResponseMessage response = new HttpResponseMessage();
                var httpRequest = HttpContext.Current.Request;
                assetQuotationId       = Convert.ToInt64(httpRequest.Form["AssetQuotationId"]);
                comments               = httpRequest.Form["Comments"];
                isAwaitingNextApproval = Convert.ToBoolean(httpRequest.Form["IsAwaitingNextApproval"]);
                loginId      = Convert.ToInt32(httpRequest.Form["LoginId"]);
                entityTypeId = Convert.ToInt64(httpRequest.Form["EntityTypeId"]);
                string AssetStatus           = string.Empty;
                bool   IsAwaitingNxtApproval = false;
                if (isAwaitingNextApproval == true)
                {
                    IsAwaitingNxtApproval = true;
                    AssetStatus           = "Awaiting Quotation Approval";
                }
                else
                {
                    AssetStatus = "Awaiting PO";
                }

                var dbAssetStatusId  = db.AssetStatus.Where(c => c.Name.ToUpper() == AssetStatus.ToUpper()).Select(x => x.Id).FirstOrDefault();
                var dbAssetRequestId = db.AssetQuotations.Where(c => c.Id == assetQuotationId).Select(x => x.AssetRequestId).FirstOrDefault();


                AssetQuoteApproval assetQuoteApproval = new AssetQuoteApproval();
                assetQuoteApproval.AssetQuotationId       = assetQuotationId;
                assetQuoteApproval.ApprovedBy             = loginId; //Need to modify
                assetQuoteApproval.ApprovedOn             = System.DateTime.Now;
                assetQuoteApproval.IsAwaitingNextApproval = IsAwaitingNxtApproval;
                assetQuoteApproval.Comments  = comments;
                assetQuoteApproval.CreatedBy = loginId;
                assetQuoteApproval.CreatedOn = System.DateTime.Now;
                db.AssetQuoteApprovals.Add(assetQuoteApproval);

                if (httpRequest.Form.Keys.Count > 0)
                {
                    var fileUpload = new AssetDocumentsController();
                    var result     = fileUpload.FileUpload(entityTypeId, loginId);
                }
                db.SaveChanges();
                var assetRequest = db.AssetRequests.SingleOrDefault(x => x.Id == dbAssetRequestId); // Add the PO Number exists in AssetRequest table
                sdate = DateTime.Now.ToShortDateString().Replace(@"-", "");

                dbMaxPONumber = db.AssetRequests.Where(a => a.PONumber != null).Count();
                dbMaxPONumber = dbMaxPONumber + 1;
                PONumber      = "PO_" + dbMaxPONumber + "_" + sdate;

                if (assetRequest != null)
                {
                    assetRequest.AssetQuotationId = assetQuotationId;
                    assetRequest.PONumber         = PONumber;
                    assetRequest.AssetStatusId    = dbAssetStatusId;
                    assetRequest.LastModifiedOn   = System.DateTime.Now;
                    db.SaveChanges();
                }
                status = "success";

                AssetHistory assetHistory = new AssetHistory();
                assetHistory.AssetRequestId   = Convert.ToInt32(dbAssetRequestId);
                assetHistory.TargetStatusId   = dbAssetStatusId;
                assetHistory.StatusChangedBy  = loginId;
                assetHistory.StatusModifiedOn = System.DateTime.Now;
                assetHistory.Comments         = comments;
                db.AssetHistories.Add(assetHistory);
                db.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
            return(Ok(status));
        }
 public AssetHistory UpdateItem(AssetHistory item)
 {
     return(logic.UpdateItem(item));
 }
 public AssetHistory AddItem(AssetHistory item)
 {
     item.CheckedOutDate = DateTime.Now;
     return(logic.AddItem(item));
 }