Exemple #1
0
        public async Task <ApplicationResult <CategoryDto> > Create(CreateCategoryViewModel model)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(model.CreatedById);

                Category mapCategory = _mapper.Map <Category>(model);
                mapCategory.CreatedById = model.CreatedById;
                mapCategory.CreatedBy   = user.UserName;
                _context.Categories.Add(mapCategory);
                await _context.SaveChangesAsync();

                ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>
                {
                    Result    = _mapper.Map <CategoryDto>(mapCategory),
                    Succeeded = true
                };

                return(result);
            }
            catch (Exception e)
            {
                ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>();
                result.Succeeded    = false;
                result.ErrorMessage = e.Message;
                return(result);
            }
        }
        public async Task <ApplicationResult <ProductDto> > Create(CreateProductViewModel model)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(model.CreatedById);

                var newProduct = _mapper.Map <Product>(model);
                newProduct.CreatedBy = user.UserName;
                await _context.Products.AddAsync(newProduct);

                await _context.SaveChangesAsync();

                return(new ApplicationResult <ProductDto>
                {
                    Succeeded = true
                });
            }
            catch (Exception e)
            {
                return(new ApplicationResult <ProductDto>
                {
                    Succeeded = true,
                    Result = new ProductDto(),
                    ErrorMessage = e.Message
                });
            }
        }
Exemple #3
0
        public async Task <ApplicationResult <BrandDto> > Create(CreateBrandViewModel model)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(model.CreatedById);

                Brand mapBrand = _mapper.Map <Brand>(model);
                mapBrand.CreatedById   = model.CreatedById;
                mapBrand.CreatedBy     = user.UserName;
                mapBrand.SubCategoryId = model.SubCategoryId;
                _context.Brands.Add(mapBrand);
                await _context.SaveChangesAsync();

                ApplicationResult <BrandDto> result = new ApplicationResult <BrandDto>
                {
                    Result    = _mapper.Map <BrandDto>(mapBrand),
                    Succeeded = true
                };

                return(result);
            }
            catch (Exception e)
            {
                ApplicationResult <BrandDto> result = new ApplicationResult <BrandDto>();
                result.Succeeded    = false;
                result.ErrorMessage = e.Message;
                return(result);
            }
        }
        public async Task <ApplicationResult <PostDto> > Create(CreatePostInput input)
        {
            try
            {
                // useri al
                var user = await _userManager.FindByIdAsync(input.CreatedById);

                // maple
                Post newPost = _mapper.Map <Post>(input);
                newPost.CreatedBy = user.UserName;
                // context e ekle
                await _context.Posts.AddAsync(newPost);

                // kaydet
                await _context.SaveChangesAsync();

                // ve dto'yu maple ve return et
                return(await Get(newPost.Id));
            }
            catch (Exception ex)
            {
                return(new ApplicationResult <PostDto>
                {
                    Result = new PostDto(),
                    Succeeded = false,
                    ErrorMessage = ex.Message
                });
            }
        }
        public async Task <IActionResult> PutCompany(int id, Company company)
        {
            if (id != company.CompanyId)
            {
                return(BadRequest());
            }

            _context.Entry(company).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompanyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #6
0
        public async Task <BazaarList> Create(CreateBazaarList input)
        {
            BazaarList newBazaarList = BazaarList.Create(input.Title, input.Description, input.CreatorUserId);
            await _context.BazaarLists.AddAsync(newBazaarList);

            await _context.SaveChangesAsync();

            return(newBazaarList);
        }
        public async Task <Books> Create(CreateBook input)
        {
            Books newBook = Books.Create(input.Name, input.Author, input.Description, input.CreatorUserId);
            await _context.Books.AddAsync(newBook);

            await _context.SaveChangesAsync();

            return(newBook);
        }
        public async Task <BookList> Create(CreateBookList input)
        {
            BookList newBookList = BookList.Create(input.Title, input.CreatorUserId);
            await _context.BookLists.AddAsync(newBookList);

            await _context.SaveChangesAsync();

            return(newBookList);
        }
        public async Task <BazaarListItem> CreateAsync(CreateBazaarListItem input)
        {
            var item = BazaarListItem.Create(input.Name, input.BazaarListId, input.CreatorUserId);

            await _context.BazaarListItems.AddAsync(item);

            await _context.SaveChangesAsync();

            return(item);
        }
        public async Task <ActionResult <Employee> > CreateEmployee(Employee employee)
        {
            if (employee == null)
            {
                throw new ArgumentNullException(nameof(employee));
            }
            _context.Employees.Add(employee);
            await _context.SaveChangesAsync();

            return(employee);
        }
        public async Task CreateAsync(CreateBookInput input)
        {
            try
            {
                Book newBook = Book.Create(input.Name, input.Price, input.ImgUrl, input.Rating, input.Binding, input.ReleaseDate, input.Details, input.PublisherId, input.AuthorId);
                await _context.Books.AddAsync(newBook);

                await _context.SaveChangesAsync();
            }
            catch (Exception err)
            {
                throw err;
            }
        }
        public async Task <NavBarMenuItem> Create(CreateNavBarMenuItemInput input)
        {
            // create'e hazir bir model olusturan metodu calistiriyor.
            NavBarMenuItem createModel = NavBarMenuItem.Create(input.Title, input.Url, input.OpenInSamePage, input.Icon, input.Roles, input.IsAnonym, input.Order);

            await OrderNumberFix(createModel.Order);

            // olusan createModel context e kaydediliyor
            await _context.NavBarMenuItems.AddAsync(createModel);

            // sonra contextteki degisiklikler veritabanina iletiliyor
            await _context.SaveChangesAsync();

            return(createModel);
        }
        /// <summary>
        /// 保存用户
        /// </summary>
        /// <param name="user"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <IdentityResult> CreateAsync(SysUser user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            await _db.AddAsync(user);

            await _db.SaveChangesAsync(cancellationToken);

            return(IdentityResult.Success);
        }
        private async Task CleanAll()
        {
            var getAll = await service.GetAll();

            inMemoryContext.RemoveRange(getAll);
            await inMemoryContext.SaveChangesAsync();
        }
Exemple #15
0
 public async Task CreateAsync(CreatePublisherInput input)
 {
     try
     {
         var newPub = new Publisher
         {
             Name = input.Name
         };
         _context.Publishers.Add(newPub);
         await _context.SaveChangesAsync();
     }
     catch (Exception err)
     {
         throw err;
     }
 }
Exemple #16
0
        private async Task CleanAll()
        {
            // tum veriyi list halinde getir
            var getAll = await inMemoryDbContext.BazaarListItems.ToListAsync();

            // ilgili tum veriyi sil
            inMemoryDbContext.RemoveRange(getAll);
            await inMemoryDbContext.SaveChangesAsync();
        }
Exemple #17
0
        public async Task <IActionResult> ViewFanfic(ApplicationUserViewModel vm)
        {
            string stringFileName = UploadFile(vm);
            var    user           = await _userManager.FindByEmailAsync(User.Identity.Name);

            user.ImageUrl = stringFileName;
            _applicationUserDbContext.ApplicationUsers.Update(user);
            await _applicationUserDbContext.SaveChangesAsync();

            return(Json(new { name = stringFileName }));
        }
Exemple #18
0
        public async Task <ActionResult <IEnumerable <Employee> > > GetAllEmployee()
        {
            var employees = new List <Employee>()
            {
                //new Employee(0,"Дмитрий","Богдагнов","Сергеевич",DateTime.Today,"Воронеж","89515511759","*****@*****.**")
            };

            _sessionRepository.Employees.AddRange(employees);
            await _sessionRepository.SaveChangesAsync();

            return(employees);
        }
        public async Task <ApplicationResult <CategoryDto> > Create(CreateCategoryInput input)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(input.CreatedById);

                Category mapCat = _mapper.Map <Category>(input);
                mapCat.CreatedById = input.CreatedById;
                mapCat.CreatedBy   = user.UserName;
                _context.Categories.Add(mapCat);
                await _context.SaveChangesAsync();

                ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>
                {
                    // haftaya bu kod yokalacak yerine automapper metodu gelecek!
                    // AutoMapper ile Category sinifini CategoryDto sinifina donusturebiliriz.
                    //Result = new CategoryDto
                    //{
                    //    CreatedById = category.CreatedById,
                    //    CreatedDate = category.CreatedDate,
                    //    CreatedBy = category.CreatedBy,
                    //    Id = category.Id,
                    //    Name = category.Name,
                    //    UrlName = category.UrlName
                    //},
                    Result    = _mapper.Map <CategoryDto>(mapCat),
                    Succeeded = true
                };

                return(result);
            }
            catch (Exception ex)
            {
                ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>();
                result.Succeeded    = false;
                result.ErrorMessage = ex.Message;
                return(result);
            }
        }
        public async Task <ApplicationResult <CategoryDto> > Create(CreateCategoryInput input)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(input.CreatedById);

                Category category = new Category
                {
                    Name        = input.Name,
                    UrlName     = input.UrlName,
                    CreatedDate = DateTime.Now,
                    CreatedById = input.CreatedById,
                    CreatedBy   = user.UserName,
                };
                _context.Categories.Add(category);
                await _context.SaveChangesAsync();

                ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>();
                // haftaya bu kod yokalacak yerine automapper metodu gelecek!
                result.Result = new CategoryDto
                {
                    CreatedById = category.CreatedById,
                    CreatedDate = category.CreatedDate,
                    CreatedBy   = category.CreatedBy,
                    Id          = category.Id,
                    Name        = category.Name,
                    UrlName     = category.UrlName
                };
                result.Succeeded = true;
                return(result);
            }
            catch (Exception e)
            {
                ApplicationResult <CategoryDto> result = new ApplicationResult <CategoryDto>();
                result.Succeeded = false;
                // TODO: hata mesajini da gonder
                return(result);
            }
        }