Example #1
0
 public ActionResult Edit(int id, AssetTypeViewModel vm)
 {
     if (ModelState.IsValid)
     {
         var assetType = Mapper.Map <AssetType>(vm);
         _unitOfWork.AssetTypes.Update(assetType);
         _unitOfWork.Complete();
         return(RedirectToAction("Index"));
     }
     return(View(vm));
 }
Example #2
0
        public async Task <UpdateAssetTypeResponse> UpdateAssetType(AssetTypeViewModel assetType)
        {
            var apiModel = new AssetTypeApiModel
            {
                AssetTypeID = assetType.AssetTypeID,
                Name        = assetType.Name
            };
            var createProductResponse = await PutEncodedContentWithSimpleResponse <UpdateAssetTypeResponse, AssetTypeApiModel>(Constants.AssetTypeUri, apiModel);

            return(createProductResponse);
        }
        public async Task <ActionResult> Edit(AssetTypeViewModel model)
        {
            var response = await _assetTypeClient.UpdateAssetType(model);

            if (response.StatusIsSuccessful)
            {
                var assetTypeId = response.Data;
                return(RedirectToAction("Index"));
            }

            AddResponseErrorsToModelState(response);
            return(View(model));
        }
        public async Task <ActionResult> Create(AssetTypeViewModel model)
        {
            var response = await _assetTypeClient.CreateAssetType(model);

            if (response.StatusIsSuccessful)
            {
                var assetTypeId = response.Data;
                return(RedirectToAction("Details", new { id = assetTypeId }));
            }

            AddResponseErrorsToModelState(response);
            return(View(model));
        }
Example #5
0
        public ActionResult Create(AssetTypeViewModel assetType)
        {
            if (ModelState.IsValid)
            {
                var asset = Mapper.Map <AssetType>(assetType);
                asset.OwnerId = User.Identity.GetUserId();
                _unitOfWork.AssetTypes.Add(asset);
                _unitOfWork.Complete();
                return(RedirectToAction("Index"));
            }

            return(View(assetType));
        }
        private async Task <ActionResult> GetAssetType(int id)
        {
            var response = await _assetTypeClient.GetAssetType(id);

            var model = new AssetTypeViewModel();

            if (response.StatusIsSuccessful)
            {
                model = Mapper.Map <AssetTypeViewModel>(response.Data);
                return(View(model));
            }

            AddResponseErrorsToModelState(response);
            return(View(model));
        }
        public async Task <IEnumerable <dynamic> > GetAssetTypeByParams(AssetTypeViewModel avm)
        {
            string sql = "dbo.EAppListAssetType";

            using (var conn = util.MasterCon())
            {
                try
                {
                    return(await(conn.QueryAsync <dynamic>(sql, new { avm.LanguageId, avm.Status }, commandType: CommandType.StoredProcedure)));
                }
                catch (Exception ex)
                {
                    throw new CustomException("Unable to Load Data, Please Contact Support!!!", "Error", true, ex);
                }
            }
        }
        public IActionResult Create(AssetTypeViewModel newAssetTypeMV)
        {
            var newAssetType = new AssetType()
            {
                Name = newAssetTypeMV.Name
            };

            try
            {
                AssetTypeManager.Add(newAssetType);
                return(RedirectToAction("Index", "Home"));
            }
            catch
            {
                return(View());
            }
        }
        // GET: AssetType/Edit/1
        public ActionResult Edit(int id)
        {
            var assetType = _assetTypeManager.Get(id);

            if (assetType == null)
            {
                return(HttpNotFound());
            }

            var assetTypeVm = new AssetTypeViewModel()
            {
                Id        = assetType.Id,
                Name      = assetType.Name,
                ShortName = assetType.ShortName,
                Code      = assetType.Code
            };

            return(View("AssetTypeForm", assetTypeVm));
        }
Example #10
0
        public async Task <IActionResult> Search([FromBody] AssetTypeViewModel avm)
        {
            try
            {
                CurrentUser cUser  = new CurrentUser(HttpContext, _configuration);
                var         result = await assetTypeRepo.GetAssetTypeByParams(avm);

                await auditLogService.LogActivity(cUser.UserId, cUser.HostIP, cUser.SessionId, "AssetType", "Asset Type List Loaded");

                return(Ok(result));
            }
            catch (CustomException cex)
            {
                var responseObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, responseObj));
            }
            catch (Exception ex)
            {
                return(Ok(new EmaintenanceMessage(ex.Message)));
            }
        }
        public ActionResult Save(AssetTypeViewModel assetTypeVm)
        {
            ModelState.Remove("Id");

            if (ModelState.IsValid)
            {
                if (assetTypeVm.Id == 0)
                {
                    bool isShortNameExist = _assetTypeManager.IsShortNameExsit(assetTypeVm.ShortName);
                    if (isShortNameExist)
                    {
                        ViewBag.Message = "This Type Short Name already Exist";
                        return(View("AssetTypeForm"));
                    }
                    var assetType = new AssetType()
                    {
                        Id        = assetTypeVm.Id,
                        Name      = assetTypeVm.Name,
                        ShortName = assetTypeVm.ShortName,
                        Code      = assetTypeVm.Code
                    };
                    _assetTypeManager.Add(assetType);
                    ModelState.Clear();
                    return(View("AssetTypeForm"));
                }

                var assetTypeInDb = _assetTypeManager.Get(assetTypeVm.Id);
                assetTypeInDb.Id        = assetTypeVm.Id;
                assetTypeInDb.Name      = assetTypeVm.Name;
                assetTypeInDb.ShortName = assetTypeVm.ShortName;
                assetTypeInDb.Code      = assetTypeVm.Code;

                _assetTypeManager.Update(assetTypeInDb);
                ModelState.Clear();
                return(View("AssetTypeList"));
            }
            return(View("AssetTypeForm", assetTypeVm));
        }
Example #12
0
        public void CreateWithValidModelShouldCreateAssetTypeAndRedirectToIndex()
        {
            // Arrange
            AssetTypeViewModel assetType = new AssetTypeViewModel
            {
                Comments = "test",
                TypeName = "debt"
            };

            string       username = "******";
            string       userid   = Guid.NewGuid().ToString("N"); //could be a constant
            List <Claim> claims   = new List <Claim> {
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", username),
                new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", userid)
            };
            var genericIdentity = new GenericIdentity("");

            genericIdentity.AddClaims(claims);
            var genericPrincipal  = new GenericPrincipal(genericIdentity, new string[] { "Asegurado" });
            var controllerContext = new Mock <ControllerContext>();

            controllerContext.SetupGet(x => x.HttpContext.User).Returns(genericPrincipal);

            Mapper.Initialize(cfg => cfg.AddProfile <AutoMapperProfile>());

            var fakeUOW       = new Mock <IUnitOfWork>();
            var fakeAssetRepo = new Mock <IGenericRepository <AssetType> >();

            fakeUOW.Setup(x => x.AssetTypes).Returns(fakeAssetRepo.Object);
            var sut = new AssetTypesController(fakeUOW.Object);

            sut.ControllerContext = controllerContext.Object;

            // act and assert
            sut.WithCallTo(x => x.Create(assetType))
            .ShouldRedirectTo(x => x.Index);
            fakeAssetRepo.Verify(x => x.Add(It.IsAny <AssetType>()), Times.Once());
        }
        public async Task <IEnumerable <dynamic> > SaveOrUpdate([FromBody] AssetTypeViewModel avm)
        {
            string sql = "dbo.EAppSaveAssetType";

            using (var conn = util.MasterCon())
            {
                try
                {
                    return(await(conn.QueryAsync <dynamic>(sql, new
                    {
                        avm.AssetTypeId,
                        avm.LanguageId,
                        avm.AssetTypeCode,
                        avm.AssetTypeName,
                        avm.Descriptions,
                        avm.Active,
                        avm.UserId
                    }, commandType: CommandType.StoredProcedure)));
                }
                catch (SqlException sqlException)
                {
                    if (sqlException.Number == 2601 || sqlException.Number == 2627)
                    {
                        throw new CustomException("Duplicate", "Asset Type Code already Exists.", "Error", true, sqlException);
                    }
                    else
                    {
                        throw new CustomException("Due to some Technical Reason, Unable to Save or Update", "Error", true, sqlException);
                    }
                }
                catch (Exception ex)
                {
                    throw new CustomException("Unable to Save Or Update, Please Contact Support!!!", "Error", true, ex);
                }
            }
        }
Example #14
0
        public async Task <IActionResult> Create([FromBody] AssetTypeViewModel avm)
        {
            try
            {
                CurrentUser cUser = new CurrentUser(HttpContext, _configuration);
                avm.UserId      = cUser.UserId;
                avm.AssetTypeId = 0;
                avm.Active      = "Y";
                var result = await assetTypeRepo.SaveOrUpdate(avm);

                await auditLogService.LogActivity(cUser.UserId, cUser.HostIP, cUser.SessionId, "AssetType", "Asset Type Created");

                return(Ok(result));
            }
            catch (CustomException cex)
            {
                var returnObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString());
                return(StatusCode(StatusCodes.Status500InternalServerError, returnObj));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new EmaintenanceMessage(ex.Message)));
            }
        }
Example #15
0
        protected override async Task OnInitializedAsync()
        {
            var id = int.Parse(Id);

            Record = await Service.Get(id);
        }
Example #16
0
        public ActionResult Create()
        {
            var model = new AssetTypeViewModel();

            return(View(model));
        }