Esempio n. 1
0
        public virtual int Save(TEntity entity)
        {
            if ((entity as IIdentityFields).Id == 0)
            {
                _dbContext.Add(entity);
            }
            else
            {
                _dbContext.Update(entity);
            }

            // history update
            if (typeof(THistory).Name.ToLower() != "object" && typeof(THistory).Name.ToLower() != "dynamic")
            {
                _dbContext.SaveChanges();
                var historyRecord = _mapper.Map <THistory>(entity);
                (historyRecord as IIAmHistory <TEntity>).Id         = 0;
                (historyRecord as IIAmHistory <TEntity>).OriginalId = (entity as IIdentityFields).Id;
                (historyRecord as IAuditFields).CreatedOn           = DateTime.Now;
                (historyRecord as IAuditFields).CreatedBy           = string.Empty;
                _dbContext.Add(historyRecord);
            }

            return(_dbContext.SaveChanges());
        }
Esempio n. 2
0
        public virtual int Save(TEntity entity, out Guid id)
        {
            if (((IIdentityFields)entity).Id == Guid.Empty)
            {
                _dbContext.Add(entity);
            }
            else
            {
                _dbContext.Update(entity);
            }

            id = ((IIdentityFields)entity).Id;
            return(_dbContext.SaveChanges());
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "UserId,BookId,Title,Content")] NewPost model)
        {
            Post post = new Post();

            if (ModelState.IsValid)
            {
                try
                {
                    post.UserId       = User.Identity.GetUserId();
                    post.Title        = model.Title;
                    post.BookId       = model.BookId;
                    post.Content      = model.Content;
                    post.SelectedBook = db.Query <Book>().FirstOrDefault(b => b.BookId == model.BookId);
                    post.User         = db.Query <ApplicationUser>().FirstOrDefault(u => u.Id == User.Identity.GetUserId());
                }
                catch
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                db.Add(post);
                db.SaveChanges();
                Book book = db.Query <Book>().FirstOrDefault(b => b.BookId == model.BookId);
                return(RedirectToAction("Details", "Books", new { id = book.BookId, page = 1 }));
            }
            return(View(post));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("ID,LastName,FirstName,DateOfBirth,Email")] Author author)
        {
            if (ModelState.IsValid)
            {
                _context.Add(author);
                await _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(author));
        }
Esempio n. 5
0
 /// <summary>
 /// Entity to create
 /// </summary>
 /// <param name="entity">Entity</param>
 public void Add(T entity)
 {
     try
     {
         _context.Add(entity);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "AuthorId,Name,ImageUrl,Description")] Author author)
        {
            if (ModelState.IsValid)
            {
                db.Add(author);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(author));
        }
        public ActionResult Create([Bind(Include = "RequestId,Title,AuthorsName,Comment")] Request request)
        {
            if (ModelState.IsValid)
            {
                db.Add(request);
                db.SaveChanges();
                return(RedirectToAction("Index", "Books"));
            }

            return(View(request));
        }
        public async Task <IActionResult> Create([Bind("Id,Content,Title")] Article article)
        {
            if (ModelState.IsValid)
            {
                _context.Add(article);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(article));
        }
        public async Task <IActionResult> Create([Bind("ID,Title,YearOfRelease,Isbn,Genre,Country,AuthorID")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChanges();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AuthorID"] = new SelectList(_context.Authors, "ID", "FullName", book.AuthorID);
            return(View(book));
        }
Esempio n. 10
0
        public int SaveOrder(Order order)
        {
            order.AddressId = _addressRepository.SaveAddress(order.Address);
            order.NetValue  = order.Items.Sum(i => i.NetValue);
            if (order.OrderId == 0)
            {
                _context.Add(order);
            }

            _context.SaveChanges();

            return(order.OrderId);
        }
Esempio n. 11
0
        public bool AddNew(TEntity newEntity, IApplicationDbContext context = null)
        {
            if (context != null)
            {
                context.Add(newEntity);
                return(context.SaveChanges() == 1);
            }

            using (var newContext = _contextFactory.Create())
            {
                newContext.Add(newEntity);
                return(newContext.SaveChanges() == 1);
            }
        }
Esempio n. 12
0
        public async Task StoreLastPosition(EventSubscriberType eventSubscriberType, long commit, long prepare)
        {
            var firstPosition = LastPosition(eventSubscriberType);

            if (firstPosition != null)
            {
                firstPosition.Update(commit, prepare);
            }
            else
            {
                _context.Add(new EventPosition(eventSubscriberType, commit, prepare));
            }

            await _context.SaveChangesAsync();
        }
Esempio n. 13
0
        public async Task <IActionResult> Create([Bind("Id,Content")] Comment comment, int id)
        {
            var thisUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if ((await _context.FindArticleById(id)) != null)
            {
                if (ModelState.IsValid)
                {
                    comment.Article_id = id;
                    comment.Author_id  = thisUserId;
                    _context.Add(comment);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Details", "Articles", new { id = id }));
                }
                return(View(comment));
            }
            return(NotFound());
        }
        public ActionResult Create(AddAuthorToBook model)
        {
            if (ModelState.IsValid)
            {
                Book book = new Book()
                {
                    Name        = model.Book.Name,
                    Genre       = model.Book.Genre,
                    Year        = model.Book.Year,
                    Rating      = model.Book.Rating,
                    Description = model.Book.Description,
                    ImageUrl    = model.Book.ImageUrl
                };

                Author author = db.Query <Author>().FirstOrDefault(a => a.AuthorId == model.SelectedAuthorId);
                if (author == null)
                {
                    model = new AddAuthorToBook()
                    {
                        Book             = new Book(),
                        Authors          = db.Query <Author>().ToList(),
                        SelectedAuthorId = -1,
                        SelectedBookId   = -1
                    };

                    return(View(model));
                }
                book.Author = author;

                db.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
 public bool Add(Localization entity)
 {
     _context.Add(entity);
     return(SaveChangesResult());
 }
 public bool CreateWebSettingsForCountry(WebSettings entity)
 {
     _context.Add(entity);
     return(SaveChangesResult());
 }
Esempio n. 17
0
 public bool Add(City entity)
 {
     _context.Add(entity);
     return(SaveChangesResult());
 }