public void Create_Should_InvokeGenericRepositoryCreate_Once()
        {
            Entity <int> outParam;

            _genericService.Create(_testEntity);
            _mockGenericRepository.Verify(x => x.TryGetOne(_testEntity.Id, out outParam, It.IsAny <bool>()), Times.Once);
            _mockGenericRepository.Verify(x => x.Create(_testEntity), Times.Once);
        }
Exemple #2
0
        public virtual async Task <string> Create(TEntity entity)
        {
            try
            {
                await service.Create(entity);

                return(GlobalConstants.DB_ENTITY_ADD_SUCCESS);
            }
            catch (Exception e)
            {
                return(GlobalConstants.DB_ENTITY_ADD_FAIL + e.StackTrace + e.Message);
            }
        }
        public void Generic_Create_Service()
        {
            var fakeContext = new FakeContext("Generic_Create_Service");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions, fakeContext.FakeConfiguration().Object))
            {
                var repository = new GenericRepository <Product>(context);
                var service    = new GenericService <Product>(repository);

                var product = new Product("1000", "Product 1", 10M, 15, new DateTime(2019, 03, 10),
                                          new DateTime(2020, 7, 14));

                var response = service.Create(product);

                Assert.Equal(6, service.GetAll().Count());
                Assert.Equal("{ Message = Produto cadastrado com sucesso. }", response.ToString());
                Assert.Equal("1000", service.GetById(6).Sku);
                Assert.Equal("Product 1", service.GetById(6).Name);
                Assert.Equal(10M, service.GetById(6).Price);
                Assert.Equal(15, service.GetById(6).Quantity);
                Assert.Equal(2019, service.GetById(6).CreatedAt.Year);
            }
        }
        public ActionResult Create(UnitsViewModel model, string redirectUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            Units units = model.Map <Units>();

            Units.Create(units);

            return(RedirectToLocal(redirectUrl));
        }
        public ActionResult Create(TypeServicesViewModel model, string redirectUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            TypeServices type = model.Map <TypeServices>();

            Types.Create(type);

            return(RedirectToLocal(redirectUrl));
        }
Exemple #6
0
        public ActionResult Create(PatientsViewModel model, string redirectUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var patient = model.Map <Patients>();

            Patient.Create(patient);

            return(RedirectToLocal(redirectUrl));
        }
        protected override void AfterSaveEntities(Dictionary <Type, List <EntityInfo> > saveMap, List <KeyMapping> keyMappings)
        {
            var uow     = new UnitOfWork(EntityConnection);
            var service = new GenericService <DatabaseLog>(null, uow, uow.DatabaseLogRepository);

            foreach (var pair in saveMap)
            {
                var entityList = pair.Value;

                foreach (var entityInfo in entityList)
                {
                    var type = entityInfo.Entity.GetType();

                    foreach (var info in pair.Value)
                    {
                        if (_strategiesAfter.ContainsKey(pair.Key))
                        {
                            _strategiesAfter[pair.Key].Execute(EntityConnection, info);
                        }

                        var id = entityInfo.Entity as IIdentifyable;
                        if (id != null)
                        {
                            var content = string.Format("Type:{0}\nKeys:{1}\nState:{2}", type.Name, id.GetId(), info.EntityState);

                            foreach (var property in info.OriginalValuesMap.Keys)
                            {
                                var originalValue = info.OriginalValuesMap[property];

                                if (originalValue != null)
                                {
                                    content += string.Format("\n{0}:{1}", property, originalValue);
                                }
                            }

                            service.Create(new DatabaseLog
                            {
                                Name      = "Log entry",
                                Content   = content,
                                CreatorId = WebSecurity.CurrentUserId
                            });
                        }
                    }
                }
            }

            uow.Commit();
            uow.DetachAll();
        }
Exemple #8
0
        public async Task <ActionResult> AddShopComment(CommentDto model)
        {
            try
            {
                model.UserId = _userService.RequestInfo.UserId;
                if (!ModelState.IsValid)
                {
                    return(Json(new AjaxResult(ModelState.JoinMessages())));
                }

                var result = await _commentService.Create(model);

                if (result.Succeeded)
                {
                    return(Json(new AjaxResult(true, Str.operationSuccessful)));
                }
                return(Json(new AjaxResult(Str.operationFailed)));
            }
            catch
            {
                return(Json(new AjaxResult(Str.operationFailed)));
            }
        }
Exemple #9
0
 public ActionResult <Circle> Create(Circle circle)
 {
     _circleService.Create(circle);
     return(CreatedAtRoute("GetCircle", new { id = circle.Id }, circle));
 }
Exemple #10
0
 public ActionResult <User> Create(User user)
 {
     _userService.Create(user);
     return(CreatedAtRoute("GetUser", new { id = user.Id }, user));
 }
Exemple #11
0
        internal async virtual Task <ActionResult <TEntity> > Post(TEntity entity, string getAction)
        {
            entity = await service.Create(entity);

            return(CreatedAtAction(getAction, new { id = entity.Id }, entity));
        }