Esempio n. 1
0
        public static AssetMaster RegisterAssetMaster(AssetMaster assetMaster)
        {
            try
            {
                using Repository <AssetMaster> repo = new Repository <AssetMaster>();
                var record = ((from asiacc in repo.AssetMaster select asiacc.Code).ToList()).ConvertAll <Int64>(Int64.Parse).OrderByDescending(x => x).FirstOrDefault();
                if (record != 0)
                {
                    // noSeries.Code = (int.Parse(lstrcd.Code) + 1).ToString();
                    assetMaster.Code = (record + 1).ToString();
                }
                else
                {
                    assetMaster.Code = "1";
                }

                assetMaster.Active = "Y";
                repo.AssetMaster.Add(assetMaster);
                if (repo.SaveChanges() > 0)
                {
                    return(assetMaster);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
 public IActionResult UpdateAssetMaster([FromBody] AssetMaster assetMaster)
 {
     if (assetMaster == null)
     {
         return(BadRequest($"{nameof(assetMaster)} cannot be null"));
     }
     try
     {
         var         result = AssetHelper.UpdateAssetMaster(assetMaster);
         APIResponse apiResponse;
         if (result != null)
         {
             apiResponse = new APIResponse()
             {
                 status = APIStatus.PASS.ToString(), response = result
             };
         }
         else
         {
             apiResponse = new APIResponse()
             {
                 status = APIStatus.FAIL.ToString(), response = "Updation Failed."
             };
         }
         return(Ok(apiResponse));
     }
     catch (Exception ex)
     {
         return(Ok(new APIResponse()
         {
             status = APIStatus.FAIL.ToString(), response = ex.Message
         }));
     }
 }
Esempio n. 3
0
        public IHttpActionResult PostAssetMaster(AssetMaster assetMaster)
        {
            db.AssetMasters.Add(assetMaster);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = assetMaster.am_id }, assetMaster));
        }
Esempio n. 4
0
        public IHttpActionResult PutAssetMaster(int id, AssetMaster assetMaster)
        {
            if (id != assetMaster.am_id)
            {
                return(BadRequest());
            }

            db.Entry(assetMaster).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AssetMasterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 5
0
        public IHttpActionResult GetAssetMaster(int id)
        {
            AssetMaster assetMaster = db.AssetMasters.Find(id);

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

            return(Ok(assetMaster));
        }
Esempio n. 6
0
        public IHttpActionResult DeleteAssetMaster(int id)
        {
            AssetMaster assetMaster = db.AssetMasters.Find(id);

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

            db.AssetMasters.Remove(assetMaster);
            db.SaveChanges();

            return(Ok(assetMaster));
        }
Esempio n. 7
0
        public IHttpActionResult PostAssetMaster(AssetMaster assetMaster)
        {
            for (int i = 0; i < count; i++)
            {
                int    min = 1000;
                int    max = 9999;
                Random rdm = new Random();
                int    id  = rdm.Next(min, max);
                assetMaster.am_snumber = id.ToString();
                db.AssetMasters.Add(assetMaster);
                db.SaveChanges();
            }



            return(CreatedAtRoute("DefaultApi", new { id = assetMaster.am_id }, assetMaster));
        }
Esempio n. 8
0
        //public async Task<IActionResult> CreateAsset([Bind("Id,FG_Code,AssetCategory,AssetType,ControllerType," +
        //     "Controllers,Trays,TraySize,Handed,Format,Power,Elements,kWh_Rating_Element,LightType,Lights,kWh_Rating_Light,Fans," +
        //      "kWh_Rating_Fan,kWh_Rating_Damper,kWh_Rating_WaterSolenoid")] AssetMaster assetMaster)
        public async Task <IActionResult> CreateAsset([Bind("Id,FG_Code,AssetCategory,AssetType,ControllerType," +
                                                            "Controllers,Trays,TraySize,Handed,Format,Power,Elements,kWh_Rating_Element,LightType,Lights,kWh_Rating_Light,Fans," +
                                                            "kWh_Rating_Fan,kWh_Rating_Damper,kWh_Rating_WaterSolenoid,CreatedBy,modifiedby")] AssetMaster assetMaster)
        {
            if (ModelState.IsValid)
            {
                var user = _userManager.GetUserId(User);
                //  var userName = _context.Users.Where(x => x.Id == user).Select(x => x.FirstName + " " + x.LastName).FirstOrDefault();
                var userName = _context.Users.Where(x => x.Id == user).Select(x => x.Id).FirstOrDefault();
                assetMaster.CreatedBy = userName;
                _context.Add(assetMaster);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(AssetsList)));
            }
            return(View(assetMaster));
        }
Esempio n. 9
0
        public static AssetMaster UpdateAssetMaster(AssetMaster assetMaster)
        {
            try
            {
                using Repository <AssetMaster> repo = new Repository <AssetMaster>();
                repo.AssetMaster.Update(assetMaster);
                if (repo.SaveChanges() > 0)
                {
                    return(assetMaster);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 10
0
        public IActionResult RegisterAssetMaster([FromBody]  AssetMaster assetMaster)
        {
            try
            {
                APIResponse apiResponse = null;

                if (AssetHelper.GetList(assetMaster.AssetNo) != null)
                {
                    return(Ok(new APIResponse()
                    {
                        status = APIStatus.FAIL.ToString(), response = $"AssetNo ={assetMaster.AssetNo} Aready Exists."
                    }));
                }

                var result = AssetHelper.RegisterAssetMaster(assetMaster);
                if (result != null)
                {
                    apiResponse = new APIResponse()
                    {
                        status = APIStatus.PASS.ToString(), response = result
                    };
                }
                else
                {
                    apiResponse = new APIResponse()
                    {
                        status = APIStatus.FAIL.ToString(), response = "Registration Failed."
                    };
                }

                return(Ok(apiResponse));
            }
            catch (Exception ex)
            {
                return(Ok(new APIResponse()
                {
                    status = APIStatus.FAIL.ToString(), response = ex.Message
                }));
            }
        }
Esempio n. 11
0
        public Message Assign(AssetMaster objUI)
        {
            Message msg = null;
            try
            {
                AssetMaster objDb = GetById(objUI.ID.ToString());

                if (objDb != null)
                {
                    Assign(objUI, objDb, ref msg);
                }
                else
                {
                    msg = new Message(MessageConstants.E0040, MessageType.Error, "Asset '" + objUI.ID + "'");
                }
            }
            catch (Exception)
            {
                msg = new Message(MessageConstants.E0007, MessageType.Error);
            }

            return msg;
        }
Esempio n. 12
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> EditAsset(int id, [Bind("Id,FG_Code,AssetCategory,AssetType,ControllerType,Controllers,Trays,TraySize,Handed,Format,Power,Elements,kWh_Rating_Element,LightType,Lights,kWh_Rating_Light,Fans," +
                                                                  "kWh_Rating_Fan,kWh_Rating_Damper,kWh_Rating_WaterSolenoid,modifiedby,CreatedBy")] AssetMaster assetMaster)

        //public async Task<IActionResult> EditAsset(int id, [Bind("Id,FG_Code,AssetCategory,AssetType,ControllerType,Controllers,Trays,TraySize,Handed,Format,Power")] AssetMaster assetMaster)
        {
            if (id != assetMaster.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var user = _userManager.GetUserId(User);
                    // var userName = _context.Users.Where(x => x.Id == user).Select(x => x.FirstName + " " + x.LastName).FirstOrDefault();
                    var userName = _context.Users.Where(x => x.Id == user).Select(x => x.Id).FirstOrDefault();
                    assetMaster.modifiedby = userName;
                    _context.Update(assetMaster);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AssetMasterExists(assetMaster.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(AssetsList)));
            }
            return(View(assetMaster));
        }
Esempio n. 13
0
        private void ReAssign(AssetMaster objUI, AssetMaster objDb, ref Message msg)
        {
            if (IsDBChanged(objUI, objDb))
            {
                if (!IsDublicateAssetId(objUI))
                {
                    objDb.AssetID = objDb.AssetID;
                    objDb.CategoryId = objDb.CategoryId;
                    objDb.StatusId = Constants.ASSIGN_ASSET_AVAILABLE_STATUS;
                    objDb.EmployeeId = Constants.ASSIGN_ASSET_EMPLOYEE_NULL;
                    objDb.Remark = objDb.Remark;
                    objDb.IsActive = objDb.IsActive;
                    objDb.UpdateDate = DateTime.Now;
                    objDb.UpdatedBy = objDb.UpdatedBy;

                    dbContext.SubmitChanges();
                }
            }
        }
Esempio n. 14
0
 public Message Insert(AssetMaster objUI)
 {
     Message msg = null;
     try
     {
         if (!IsDublicateAssetId(objUI))
         {
             dbContext.AssetMasters.InsertOnSubmit(objUI);
             dbContext.SubmitChanges();
             msg = new Message(MessageConstants.I0001, MessageType.Info, "Asset Master '" + objUI.AssetID + "'", "added");
         }
         else
         {
             msg = new Message(MessageConstants.E0020, MessageType.Error, "Name '" + objUI.AssetID + "'", "Asset Master");
         }
     }
     catch (Exception)
     {
         msg = new Message(MessageConstants.E0007, MessageType.Error);
     }
     return msg;
 }
Esempio n. 15
0
        private void Assign(AssetMaster objUI, AssetMaster objDb, ref Message msg)
        {
            if (IsDBChanged(objUI, objDb))
            {
                if (!IsDublicateAssetId(objUI))
                {
                    objDb.AssetID = objDb.AssetID;
                    objDb.CategoryId = objDb.CategoryId;
                    objDb.StatusId = Constants.ASSIGN_ASSET_INUSE_STATUS;
                    objDb.EmployeeId = (String.IsNullOrEmpty(objUI.EmployeeId)) ? null : objUI.EmployeeId; ;
                    objDb.Remark = objDb.Remark;
                    objDb.IsActive = objDb.IsActive;
                    objDb.UpdateDate = DateTime.Now;
                    objDb.UpdatedBy = objDb.UpdatedBy;

                    dbContext.SubmitChanges();
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Add and Edit Document
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public CommonResponseWithIds AddAndEditAsset(AssetCustom data, long userId = 0)
        {
            CommonResponseWithIds obj = new CommonResponseWithIds();

            try
            {
                var res = db.AssetMaster.Where(m => m.AssetId == data.assetId).FirstOrDefault();
                if (res == null)
                {
                    try
                    {
                        AssetMaster item = new AssetMaster();
                        item.AssetName               = data.assetName;
                        item.AssetDescription        = data.assetDescription;
                        item.AssetDocumentUploadedId = data.assetDocumentUploadedId;
                        item.BarcodeAllocatedNumber  = data.barcodeAllocatedNumber;
                        item.LineNumber              = data.lineNumber;
                        item.IsActive  = true;
                        item.IsDeleted = false;
                        item.CreatedBy = userId;
                        item.CreatedOn = DateTime.Now;
                        db.AssetMaster.Add(item);
                        db.SaveChanges();
                        obj.response = ResourceResponse.AddedSucessfully;
                        obj.isStatus = true;
                        obj.id       = item.AssetId;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
                else
                {
                    try
                    {
                        res.AssetName               = data.assetName;
                        res.AssetDescription        = data.assetDescription;
                        res.AssetDocumentUploadedId = data.assetDocumentUploadedId;
                        res.BarcodeAllocatedNumber  = data.barcodeAllocatedNumber;
                        res.LineNumber              = data.lineNumber;
                        res.ModifiedBy              = userId;
                        res.ModifiedOn              = DateTime.Now;
                        db.SaveChanges();
                        obj.id       = res.AssetId;
                        obj.response = ResourceResponse.UpdatedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex); if (ex.InnerException != null)
                {
                    log.Error(ex.InnerException.ToString());
                }
                obj.response = ResourceResponse.ExceptionMessage;
                obj.isStatus = false;
            }
            return(obj);
        }
Esempio n. 17
0
        private void Delete(AssetMaster objUI)
        {
            if (objUI != null)
            {
                // Get current group in dbContext
                AssetMaster objDb = GetById(objUI.ID.ToString());
                if (objDb != null)
                {
                    // Set delete info
                    objDb.DeleteFlag = true;
                    objDb.UpdateDate = DateTime.Now;
                    objDb.UpdatedBy = objUI.UpdatedBy;
                    // Submit changes to dbContext
                    dbContext.SubmitChanges();

                }
            }
        }
Esempio n. 18
0
 private bool IsDBChanged(AssetMaster objUI, AssetMaster objDb)
 {
     bool isChannged = true;
     if (objDb.UpdateDate.ToString() == objUI.UpdateDate.ToString())
     {
         isChannged = false;
     }
     return isChannged;
 }
        public Task <bool> UpdateAsync(AssetMasterVM entity)
        {
            return(Task.Run(() =>
            {
                if (entity.Asset_Base64_Photo != null)
                {
                    string base64 = entity.Asset_Base64_Photo;
                    entity.Asset_Base64_Photo = String.Format(base64);
                    base64 = base64.Remove(0, base64.IndexOf("base64,") + 7);
                    entity.AssetPhoto = Convert.FromBase64String(base64);
                }

                AssetMaster assetMaster = new AssetMaster
                {
                    ID = entity.ID,
                    Code = entity.Code,
                    ARName = entity.ARName,
                    LatName = entity.LatName,
                    AssetGroupID = entity.AssetGroupID,
                    AssetAccountID = entity.AssetAccountID,
                    AssetBrand = entity.AssetBrand,
                    AssetColor = entity.AssetColor,
                    AssetHeight = entity.AssetHeight,
                    AssetLocation = entity.AssetLocation,
                    AssetModel = entity.AssetModel,
                    AssetScreenNumber = entity.AssetScreenNumber,
                    AssetStatusID = entity.AssetStatusID,
                    AssetTypeID = entity.AssetTypeID,
                    AssetWeight = entity.AssetWeight,
                    AssetWidth = entity.AssetWidth,
                    Barcode = entity.Barcode,
                    ManufactureCompanyID = entity.ManufactureCompanyID,
                    OriginNationID = entity.OriginNationID,
                    SupplierCompanyID = entity.SupplierCompanyID,
                    DepreciationAccountID = entity.DepreciationAccountID,
                    TotalDepreciationAccountID = entity.TotalDepreciationAccountID,
                    ExpensesAccountID = entity.ExpensesAccountID,
                    CapitalProfitAccountID = entity.CapitalProfitAccountID,
                    CapitalLossAccountID = entity.CapitalLossAccountID,
                    AppraisalExcessAccountID = entity.AppraisalExcessAccountID,
                    ApprasialDeficitAccountID = entity.ApprasialDeficitAccountID,
                    AssetPhoto = entity.AssetPhoto,
                    AddedBy = entity.AddedBy,
                    AddedOn = entity.AddedOn,
                    UpdatedBy = entity.UpdatedBy,
                    UpdatedOn = DateTime.Now,
                    Notes = entity.Notes,
                    DepartmentID = entity.DepartmentID,
                    ManufactureDate = entity.ManufactureDate,
                    WarrantyNumber = entity.WarrantyNumber,
                    WarrantyStartDate = entity.WarrantyStartDate,
                    WarrantyEndDate = entity.WarrantyEndDate,
                    ReceivingDate = entity.ReceivingDate,
                    ReceivingNotes = entity.ReceivingNotes,
                    ContractNumber = entity.ContractNumber,

                    ContractDate = entity.ContractDate,
                    PurchasingDate = entity.PurchasingDate,
                    CustomsStatment = entity.CustomsStatment,
                    CustomsStatmentDate = entity.CustomsStatmentDate,

                    ShippingNumber = entity.ShippingNumber,
                    AssetShippingMethodID = entity.AssetShippingMethodID,
                    ShippingDate = entity.ShippingDate,
                    ImportLicenseNumber = entity.ImportLicenseNumber,
                    ShippingDestination = entity.ShippingDestination,
                    ShippingArrivalDate = entity.ShippingArrivalDate,
                    //Active = entity.Active,
                    //Position = entity.Position
                };
                assetMasterRepo.Update(assetMaster, assetMaster.ID);

                AssetDepreciationDetails assetDepreciationDetails = new AssetDepreciationDetails
                {
                    ID = entity.Depreciation.ID,
                    //Active = entity.Depreciation.Active,
                    AddedBy = entity.Depreciation.AddedBy,
                    AddedOn = entity.Depreciation.AddedOn,
                    AssetDepreciationTypeID = entity.Depreciation.AssetDepreciationTypeID,
                    //Position = entity.Depreciation.Position,
                    AssetLifeSpan = entity.Depreciation.AssetLifeSpan,
                    AssetLifeSpanUnitID = entity.Depreciation.AssetLifeSpanUnitID,
                    AssetMasterID = assetMaster.ID,
                    AssetScrapValue = entity.Depreciation.AssetScrapValue,
                    CurrencyID = entity.Depreciation.CurrencyID,
                    CurrencyRate = entity.Depreciation.CurrencyRate,
                    CurrentAssetValue = entity.Depreciation.CurrentAssetValue,
                    DepreciationStartDate = entity.Depreciation.DepreciationStartDate,
                    DepreciationTotals = entity.Depreciation.DepreciationTotals,
                    ExclusionsValue = entity.Depreciation.ExclusionsValue,
                    ExtraValue = entity.Depreciation.ExtraValue,
                    InitialAssetScrapValue = entity.Depreciation.InitialAssetScrapValue,
                    Notes = entity.Depreciation.Notes,
                    NotSubjectToDepreciation = entity.Depreciation.NotSubjectToDepreciation,
                    NotSubjectToRevaluation = entity.Depreciation.NotSubjectToRevaluation,
                    UpdatedBy = entity.Depreciation.UpdatedBy,
                    UpdatedOn = DateTime.Now
                };
                AssetDepreciationDetailsRepo.Update(assetDepreciationDetails, assetDepreciationDetails.ID);
                return true;
            }));
        }
Esempio n. 20
0
        private void Update(AssetMaster objUI, AssetMaster objDb, ref Message msg)
        {
            if (!IsDBChanged(objUI, objDb))
            {
                if (!IsDublicateAssetId(objUI))
                {
                    objDb.AssetID = objUI.AssetID;
                    objDb.CategoryId = objUI.CategoryId;
                    objDb.StatusId = objUI.StatusId;
                    objDb.EmployeeId = (String.IsNullOrEmpty(objUI.EmployeeId)) ? null : objUI.EmployeeId;
                    objDb.Remark = objUI.Remark;
                    objDb.IsActive = objUI.IsActive;
                    objDb.UpdateDate = DateTime.Now;
                    objDb.UpdatedBy = objUI.UpdatedBy;

                    dbContext.SubmitChanges();
                    msg = new Message(MessageConstants.I0001, MessageType.Info, "Asset Master '" + objUI.AssetID + "'", "updated");
                }
                else
                {
                    msg = new Message(MessageConstants.E0020, MessageType.Error, "'" + objUI.AssetID + "'", "Asset Property");
                }
            }
            else
            {
                msg = new Message(MessageConstants.E0025, MessageType.Error, "Asset Master'" + objDb.AssetID + "'");
            }
        }
Esempio n. 21
0
 private bool IsDublicateAssetId(AssetMaster objUI)
 {
     bool isDublicateName = true;
     AssetMaster dublicateName = dbContext.AssetMasters.Where(a => a.AssetID.Equals(objUI.AssetID) && a.DeleteFlag == false).FirstOrDefault<AssetMaster>();
     if (dublicateName == null || dublicateName.ID == objUI.ID)
     {
         isDublicateName = false;
     }
     return isDublicateName;
 }