public async Task <IActionResult> AddAndEditAsset(AssetCustom data)
        {
            #region Authorization code
            var    identity = HttpContext.User.Identity as ClaimsIdentity;
            string id       = "";
            string role     = "";
            if (identity != null)
            {
                IEnumerable <Claim> claims = identity.Claims;
                // or
                id   = identity.Claims.Where(m => m.Type == ClaimTypes.Sid).Select(m => m.Value).FirstOrDefault();
                role = identity.Claims.Where(m => m.Type == ClaimTypes.Role).Select(m => m.Value).FirstOrDefault();
            }
            long userId = Convert.ToInt32(id);
            #endregion
            //calling AssetDAL busines layer
            CommonResponseWithIds response = new CommonResponseWithIds();
            response = asset.AddAndEditAsset(data, userId);

            return(Ok(response));
        }
Exemplo n.º 2
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);
        }