public async Task <IActionResult> AddStore(StoreModel storeModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    (bool isOk, int id) = await storeManager.AddAsync(new StoreStruct
                    {
                        Name         = storeModel.Name,
                        Address      = storeModel.Address,
                        WorkingHours = storeModel.WorkingHours
                    });

                    storeModel.Id = id;
                    return(PartialView("SingleStore", storeModel));
                }
                catch (ExistsInDBException e)
                {
                    ViewData["Errors"] = e.Message;
                }
            }
            else
            {
                ViewData["Errors"] = "The field can not be empty";
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Content(ViewData["Errors"].ToString()));
        }
        public async Task <IActionResult> AddProduct(ProductModel productModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    (bool isOk, int id) = await productManager.AddAsync(new ProductStruct
                    {
                        Name        = productModel.Name,
                        Description = productModel.Description
                    });

                    productModel.Id = id;
                    return(PartialView("SingleProduct", productModel));
                }
                catch (ExistsInDBException e)
                {
                    ViewData["Errors"] = e.Message;
                }
            }
            else
            {
                ViewData["Errors"] = "The field can not be empty";
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(Content(ViewData["Errors"].ToString()));
        }
Esempio n. 3
0
        public async Task <Result> AddAsync(UserLogic user, UserLogic userY)
        {
            try
            {
                if (userY.IsAdmin)
                {
                    user.Id = Guid.NewGuid().ToString();
                    user.RegistrationDate = DateTime.Now;
                    var userDb = mapper.Map <UserLogic, UserDb>(user);
                    var result = await dbmanager.AddAsync(userDb);

                    return(Result.Ok());
                }
                else
                {
                    return(Result.Fail("Unauthorized"));
                }
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (DbUpdateException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (DbEntityValidationException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (Exception)
            {
                return(Result.Fail("Exception"));
            }
        }
Esempio n. 4
0
        public async Task <Result> AddAsync(CommentLogic comment)
        {
            try
            {
                comment.Id       = Guid.NewGuid().ToString();
                comment.PostDate = DateTime.Now;
                var commentDb = mapper.Map <CommentLogic, CommentDb>(comment);
                var result    = await dbmanager.AddAsync(commentDb);

                return(Result.Ok());
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (DbUpdateException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (DbEntityValidationException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (Exception)
            {
                return(Result.Fail("Exception"));
            }
        }
Esempio n. 5
0
        public async Task <Result> AddAsync(CourseLogic course, UserLogic user)
        {
            try
            {
                course.Id           = Guid.NewGuid().ToString();
                course.Author       = user;
                course.CreationDate = DateTime.Now;
                course.Raiting      = null;
                course.Duration     = course.Audios.Aggregate(0, (x, y) => x + y.Duration);
                user.UploadedCourses.Add(course);
                var userDb   = mapper.Map <UserLogic, UserDb>(user);
                var courseDb = mapper.Map <CourseLogic, CourseDb>(course);
                await UdbManager.UpdateAsync(userDb);

                var result = await dbmanager.AddAsync(courseDb);

                return(Result.Ok());
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (DbUpdateException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (DbEntityValidationException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (Exception)
            {
                return(Result.Fail("Exception"));
            }
        }
Esempio n. 6
0
        public async Task <Result> AddAsync(AudioLogic audio, UserLogic user)
        {
            try
            {
                if (user.UploadedCourses.Contains(audio.Course) || user.IsAdmin)
                {
                    var course = audio.Course;
                    audio.Content = Guid.NewGuid().ToString();
                    audio.Id      = Guid.NewGuid().ToString();
                    var audioDb = mapper.Map <AudioLogic, AudioDb>(audio);
                    var result  = await dbmanager.AddAsync(audioDb);

                    return(Result.Ok());
                }
                else
                {
                    return(Result.Fail("Unauthorized"));
                }
            }
            catch (DbUpdateConcurrencyException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (DbUpdateException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (DbEntityValidationException e)
            {
                return(Result.Fail(e.Message));
            }
            catch (Exception)
            {
                return(await Task.FromResult(Result.Fail("Exception")));
            }
        }
Esempio n. 7
0
        public async Task <Result> AddAsync(ContentLogic content, UserLogic user)
        {
            try
            {
                var audio = content.Audio;
                if (user.UploadedCourses.Any(c => c.Audios.Contains(audio)) || user.IsAdmin)
                {
                    content.Audio = audio;
                    content.Id    = audio.Content;
                    var contentDb = mapper.Map <ContentLogic, ContentDb>(content);
                    await dbmanager.AddAsync(contentDb);

                    return(Result.Ok());
                }
                else
                {
                    return(Result.Fail("Unauthorized"));
                }
            }
            catch (Exception)
            {
                return(Result.Fail("Exception"));
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Create entity
        /// Signature: api/entity
        /// </summary>
        /// <param name="model">Entity domain model</param>
        /// <returns>IActionResult encapsulating Entity domain model mapped from created entity</returns>

        public virtual async Task <IActionResult> Create([FromBody] T model)
        {
            var result = await DomainManager.AddAsync(model);

            return(new ContentActionResult <T>(HttpStatusCode.OK, result, "OK", Request));
        }
Esempio n. 9
0
 public async Task <DeliveryIntervalDto> PostAsync(DeliveryIntervalForCreateModel value)
 {
     return(await _repository.AddAsync(Mapper.Map <DeliveryIntervalDto>(value)));
 }