Example #1
0
        public ActionResult Create(Application.Entities.Facility model)
        {
            var baseObject = GetBaseObject();

            if (!baseObject.User.IsSuperAdmin)
            {
                new BusinessRuleException("Access Denied");
            }

            _facilityService.Create(model);

            return(RedirectToAction("List", "Facility"));
        }
        public void Create_ValidModel_ReturnId(int newId)
        {
            //arrange
            var newItem = new Facility();

            //act
            var service  = new FacilityService(_facilityRepository.Object, _logger.Object);
            var returnId = service.Create(newItem);

            //assert
            Assert.Equal(newId, returnId);
            Assert.NotEqual(0, newItem.Id);
            Assert.NotEqual(DateTime.MinValue, newItem.Created);
            Assert.True(_data.Count == 2);
        }
Example #3
0
        public ActionResult Create(facility facility)
        {
            if (ModelState.IsValid)
            {
                if (_facilityService.IsAlreadyExists(facility))
                {
                    ModelState.AddModelError("fac_name", $"Facility {facility.fac_name} already exists");
                }
                else
                {
                    facility.facility_contract.fct_created_by   = User.Identity.GetUserId();
                    facility.facility_contract.fct_created_date = DateTime.Now.ToEST();
                    facility.fac_key             = Guid.NewGuid();
                    facility.fac_created_by      = User.Identity.GetUserId();
                    facility.fac_created_date    = DateTime.Now.ToEST();
                    facility.fac_created_by_name = loggedInUser.FullName;
                    if (!string.IsNullOrEmpty(facility.facility_contract.fct_selected_services))
                    {
                        try
                        {
                            string[] _services = facility.facility_contract.fct_selected_services.Split(',');
                            bool     isFind    = _services.Contains("335");
                            if (isFind)
                            {
                                facility.fac_is_pac = true;
                            }
                            else
                            {
                                facility.fac_is_pac = false;
                            }
                        }
                        catch (Exception e)
                        {
                            facility.fac_is_pac = false;
                        }
                    }
                    _facilityService.Create(facility);

                    // Adding default selected facility contract
                    SaveFacilityContract(facility.facility_contract);

                    return(GetSuccessResult(Url.Action("Edit", new { id = facility.fac_key, showPopupOnLoad = User.IsInRole(UserRoles.FacilityAdmin.ToDescription()) ? false : ApplicationSetting.aps_cas_facility_popup_on_load }), "Facility successfully added"));
                    //return GetSuccessResult();
                }
            }

            return(GetErrorResult(facility));
        }
        public void Create_ValidModel_ReturnFacilityId()
        {
            //arrange
            _facilityRepository.Setup(a => a.Create(It.IsAny <Facility>())).Returns(2).Callback((Facility c) =>
            {
                c.Id = _data.Count + 1;
                _data.Add(c);
            });
            var model = new Facility();

            //act
            var service = new FacilityService(_facilityRepository.Object);

            service.Create(model);

            //assert
            Assert.IsNotNull(model.Created);
            Assert.IsNotNull(model.Id);
            Assert.IsTrue(_data.Count == 2);
        }