コード例 #1
0
        public IActionResult GetAllUsersOrderByName()
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    var users = context.User.Where(x => x.IsDeleted == false).OrderBy(x => x.Username).ToList();

                    List <UserDTO> userList = new List <UserDTO>();
                    if (users.Count > 0)
                    {
                        foreach (var item in users)
                        {
                            item.Password = null;
                            userList.Add(Mapper.Map <UserDTO>(item));
                        }

                        return(apiJsonResponse.ApiOkContentResult(userList));
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                    }
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #2
0
        public IActionResult GetProductNameByBarcodeId(BarcodeDTO barcodeDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (barcodeDTO.BarcodeId != string.Empty)
                {
                    using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                    {
                        if (context.Products.Any(x => x.BarcodeId == barcodeDTO.BarcodeId && x.IsDeleted == false))

                        {
                            var barcodeIdAndNameDTO = new BarcodeIdAndNameDTO();
                            barcodeIdAndNameDTO.BarcodeId   = barcodeDTO.BarcodeId;
                            barcodeIdAndNameDTO.ProductName = context.Products.FirstOrDefault(x => x.BarcodeId == barcodeIdAndNameDTO.BarcodeId && x.IsDeleted == false).ProductName;

                            return(apiJsonResponse.ApiOkContentResult(barcodeIdAndNameDTO));
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductNotFound));
                        }
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #3
0
        public IActionResult GetUserDetailByUsername(UserDTO userDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    var user = context.User.FirstOrDefault(x => x.Username == userDTO.Username && x.IsDeleted == false);

                    if (user != null)
                    {
                        user.Password = null;
                        return(apiJsonResponse.ApiOkContentResult(Mapper.Map <UserDTO>(user)));
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                    }
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #4
0
        public IActionResult UpdateEmail(UpdateEmailDTO updateEmailDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (context.User.Any(x => x.IsDeleted == false && x.Email == updateEmailDTO.oldEmail))
                    {
                        if (context.User.Any(x => x.IsDeleted == false && x.Email == updateEmailDTO.newEmail))
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNameOrEmailAlreadyExistError));
                        }
                        else
                        {
                            var User = context.User.FirstOrDefault(x => x.IsDeleted == false && x.Email == updateEmailDTO.oldEmail);
                            User.Email        = updateEmailDTO.newEmail;
                            User.ModifiedDate = DateTime.Now;

                            context.SaveChanges();
                            return(apiJsonResponse.ApiOkContentResult(updateEmailDTO));
                        }
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                    }
                }
            }
            catch
            { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); }
        }
コード例 #5
0
        public IActionResult UpdatePassword(UpdatePasswordDTO updatePasswordDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (context.User.Any(x => x.IsDeleted == false && x.Username == updatePasswordDTO.Username))
                    {
                        var User = context.User.FirstOrDefault(x => x.IsDeleted == false && x.Username == updatePasswordDTO.Username);
                        if (updatePasswordDTO.NewPassword != string.Empty)
                        {
                            User.Password     = HelperFunctions.ComputeSha256Hash(updatePasswordDTO.NewPassword);
                            User.ModifiedDate = DateTime.Now;
                            context.SaveChanges();
                            return(apiJsonResponse.ApiOkContentResult(updatePasswordDTO));
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.PasswordRequired));
                        }
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                    }
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #6
0
        public IActionResult AllProduct()
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    var products    = context.Products.Where(x => x.IsDeleted == false).OrderByDescending(x => x.CreatedDate).ToList();
                    var productsDTO = new List <ProductDTO>();
                    foreach (var item in products)
                    {
                        item.FirstImage  = null;
                        item.SecondImage = null;
                        item.ThirdImage  = null;

                        productsDTO.Add(Mapper.Map <ProductDTO>(item));
                    }
                    return(apiJsonResponse.ApiOkContentResult(productsDTO));
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #7
0
        public IActionResult UpdateContent(ContentDTO contentDTO)

        //Product->BarcodeId && Language-> LanguageCode is necessary
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (contentDTO != null)
                {
                    using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                    {
                        if (context.ProductContents.Any(x => x.Product.BarcodeId == contentDTO.Product.BarcodeId && x.Language.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false))
                        {
                            if (contentDTO.NutritionFact != null)
                            {
                                var content = context.ProductContents.Where(x => x.Product.BarcodeId == contentDTO.Product.BarcodeId && x.Language.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false).FirstOrDefault();



                                contentDTO.NutritionFact.ID = 0;
                                content.NutritionFact       = Mapper.Map <NutritionFacts>(contentDTO.NutritionFact);
                                content.CookingTips         = contentDTO.CookingTips;
                                content.Details             = contentDTO.Details;
                                content.Ingredients         = contentDTO.Ingredients;
                                content.Language            = Mapper.Map <Language>(contentDTO.Language);
                                content.Recommendations     = contentDTO.Recommendations;
                                content.VideoURL            = contentDTO.VideoURL;
                                content.Warnings            = contentDTO.Warnings;
                                content.ModifiedDate        = DateTime.Now;
                                if (contentDTO.ModifiedUserId == null)
                                {
                                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ModifiedUserIdRequired));
                                }
                                content.ModifiedUserId = contentDTO.ModifiedUserId;
                                context.SaveChanges();
                                return(apiJsonResponse.ApiOkContentResult(contentDTO));
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                            }
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                        }
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #8
0
        public IActionResult AddCategory(CategoryNameDTO category)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try

            {
                if (category != null)
                {
                    if (category.CategoryName != string.Empty && category.LanguageCode != string.Empty)
                    {
                        using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                        {
                            if (!context.ProductCategories.Any(x => x.CategoryName == category.CategoryName && x.IsDeleted == false && x.LanguageCode == category.LanguageCode))
                            {
                                if (context.Languages.Any(x => x.LanguageCode == category.LanguageCode && x.IsDeleted == false))
                                {
                                    if (category.CreatedUserId == null)
                                    {
                                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideACreatedUserId));
                                    }
                                    context.ProductCategories.Add(Mapper.Map <ProductCategory>(category));
                                    context.SaveChanges();
                                    var lastItem = context.ProductCategories.Last();
                                    category.ID = lastItem.ID;
                                    category.Id = lastItem.ID;
                                    return(apiJsonResponse.ApiOkContentResult(category));
                                }
                                else
                                {
                                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideLanguageCode));
                                }
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessageAndObject(category, PublicConstants.AlreadyACategoryDefinedWithThisName));
                            }
                        }
                    }


                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideCategoryName));
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }

            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #9
0
        public IActionResult SetInitialImagesByBarcodeId(ImageDTO imageDto)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (imageDto != null)
                {
                    using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                    {
                        if (context.Products.Any(x => x.BarcodeId == imageDto.BarcodeId && x.IsDeleted == false))
                        {
                            var product = context.Products.FirstOrDefault(x =>
                                                                          x.BarcodeId == imageDto.BarcodeId && x.IsDeleted == false);
                            if (imageDto.FirstImage == null && imageDto.SecondImage == null && imageDto.ThirdImage == null)

                            {
                                return
                                    (apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideAtLeastOneImage));
                            }

                            if (imageDto.FirstImage != null)
                            {
                                product.FirstImage = imageDto.FirstImage;
                            }

                            if (imageDto.SecondImage != null)
                            {
                                product.SecondImage = imageDto.SecondImage;
                            }

                            if (imageDto.ThirdImage != null)
                            {
                                product.ThirdImage = imageDto.ThirdImage;
                            }

                            context.SaveChanges();

                            return(apiJsonResponse.ApiOkContentResult());
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductNotFound));
                        }
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #10
0
        public IActionResult AddComment(CommentDTO commentDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (commentDTO != null)
                {
                    if (commentDTO.UserComment == string.Empty)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.CommentCanNotBeEmpty));
                    }
                    else
                    {
                        using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                        {
                            Comment comment = new Comment();
                            try
                            {
                                comment.ProductContent = context.ProductContents.Where(x => x.ID == commentDTO.ProductContentId)
                                                         .Include(m => m.Product)
                                                         .Include(m => m.NutritionFact)
                                                         .Include(m => m.Language)
                                                         .Include(m => m.NutritionFact)
                                                         .FirstOrDefault();
                            }
                            catch
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductContentIdRequired));
                            }

                            comment.UserComment = commentDTO.UserComment;
                            if (commentDTO.CreatedUserId == null)
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideACreatedUserId));
                            }
                            comment.CreatedUserId = commentDTO.CreatedUserId;

                            context.Add(comment);
                            context.SaveChanges();
                            return(apiJsonResponse.ApiOkContentResult(commentDTO));
                        }
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }

            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #11
0
        public IActionResult AddVote(VoteDTO voteDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (voteDTO != null)

                {
                    if (voteDTO.UserVote != null && voteDTO.CreatedUserId != null && voteDTO.BarcodeID != string.Empty)
                    {
                        using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                        {
                            if (context.Products.Any(x => x.BarcodeId == voteDTO.BarcodeID && x.IsDeleted == false))
                            {
                                var vote = new Vote();
                                vote.Product = context.Products.Where(x => x.BarcodeId == voteDTO.BarcodeID && x.IsDeleted == false).FirstOrDefault();

                                if (context.Votes.Any(x => x.CreatedUserId == voteDTO.CreatedUserId && x.Product.ID == vote.Product.ID && vote.IsDeleted == false))
                                {
                                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserAlreadyVoteThisProduct));
                                }


                                vote.UserVote      = voteDTO.UserVote;
                                vote.CreatedUserId = voteDTO.CreatedUserId;

                                context.Add(vote);
                                context.SaveChanges();
                                return(apiJsonResponse.ApiOkContentResult(voteDTO));
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductNotFound));
                            }
                        }
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                    }
                }

                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #12
0
        public IActionResult GroupProducts(GroupProductsDTO groupProdutsDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (groupProdutsDTO != null)
                {
                    using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                    {
                        var product = context.Products.OrderByDescending(x => x.ProductGroupId).FirstOrDefault();
                        if (groupProdutsDTO.ModifiedUserId == null)
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ModifiedUserIdRequired));
                        }


                        if (groupProdutsDTO.BarcodeId.Count < 2)
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.PleaseSelectMoreThanOneProduct));
                        }
                        foreach (var item in groupProdutsDTO.BarcodeId)
                        {
                            var groupedProduct = context.Products.Where(x => x.BarcodeId == item).FirstOrDefault();
                            if (groupedProduct == null)
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductNotFound));
                            }
                            if (groupedProduct.ProductGroupId != 0)
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductHasAlreadyGroup));
                            }
                            groupedProduct.ProductGroupId  = product.ProductGroupId + 1;
                            groupedProduct.ModifiedUserId  = groupProdutsDTO.ModifiedUserId;
                            groupedProduct.ModifiedDate    = DateTime.Now;
                            groupProdutsDTO.ProductGroupId = groupedProduct.ProductGroupId;
                        }

                        context.SaveChanges();
                        return(apiJsonResponse.ApiOkContentResult(groupProdutsDTO));
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #13
0
        public IActionResult UpdateCategoryName(UpdateCategoryNameDTO categoryNameDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (categoryNameDTO != null)
                    {
                        var result = context.ProductCategories.FirstOrDefault(x => x.CategoryName == categoryNameDTO.OldCategoryName);
                        if (result != null)
                        {
                            if (result.IsDeleted == false)
                            {
                                result.ModifiedDate = DateTime.Now;
                                if (categoryNameDTO.ModifiedUserId == null)

                                {
                                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProivdeModifiedUserId));
                                }


                                result.ModifiedUserId = categoryNameDTO.ModifiedUserId;
                                result.CategoryName   = categoryNameDTO.NewCategoryName;
                                context.SaveChanges();
                                return(apiJsonResponse.ApiOkContentResult(categoryNameDTO));
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.NoCategoryFound));
                            }
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.NoCategoryFound));
                        }
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                    }
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #14
0
        public IActionResult SearchProductByName(string productName)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (productName != string.Empty)
                {
                    using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                    {
                        if (productName.Length >= 3)
                        {
                            List <SearchByNameDTO> searchByNameDTOs = new List <SearchByNameDTO>();
                            try
                            {
                                List <Product> products = context.Products.Where(x => x.ProductName.Contains(productName) && x.IsDeleted == false).ToList();

                                if (products.Count == 0)
                                {
                                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductNotFound));
                                }
                                foreach (var item in products)
                                {
                                    searchByNameDTOs.Add(Mapper.Map <SearchByNameDTO>(item));
                                }

                                return(apiJsonResponse.ApiOkContentResult(searchByNameDTOs));
                            }
                            catch
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductNotFound));
                            }
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductNotFound));
                        }
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }
            catch (Exception)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #15
0
        public IActionResult GetFirstUser()
        {
            var apiJsonResponse = new ApiJsonResponse();

            //return Ok(new ApiResponse((int)HttpStatusCode.BadRequest, "Sistem Hatası"));
            //return BadRequest(new ApiBadRequestResponse(ModelState));
            using (FoodInfoServiceContext foodInfoServiceContext = new FoodInfoServiceContext())
            {
                var user = foodInfoServiceContext.User.FirstOrDefault();

                if (user == null)
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                }
                return(apiJsonResponse.ApiOkContentResult(Mapper.Map <UserDTO>(user)));
            }
        }
コード例 #16
0
        public IActionResult GetProductCategoriesByLanguageCode(LanguageCodeDTO languageCodeDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (languageCodeDTO.LanguageCode != string.Empty)
                {
                    using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                    {
                        var categories = context.ProductCategories.Where(x => x.IsDeleted == false && x.LanguageCode == languageCodeDTO.LanguageCode).ToList();
                        if (categories != null && categories.Count != 0)
                        {
                            List <CategoryNameDTO> categoryNames = new List <CategoryNameDTO>();

                            foreach (var item in categories)
                            {
                                categoryNames.Add(Mapper.Map <CategoryNameDTO>(item));
                            }
                            if (categoryNames != null)
                            {
                                return(apiJsonResponse.ApiOkContentResult(categoryNames));
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.NoCategoryFound));
                            }
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.NoCategoryFound));
                        }
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideLanguageCode));
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #17
0
        public IActionResult GetErrorList()
        {
            var apiJsonResponse = new ApiJsonResponse();
            try
            {

                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {

                    var errors = context.Errors.Where(x => x.IsDeleted == false ).ToList();
                    if (errors != null)
                    {
                        List<ErrorDTO> errorDTOs= new List<ErrorDTO>();
                        foreach(var item in errors)
                        {
                            errorDTOs.Add(Mapper.Map<ErrorDTO>(item));

                        }
                        if (errorDTOs != null)
                        {
                            return apiJsonResponse.ApiOkContentResult(errorDTOs);
                        }
                        else
                        {
                            return apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage + " Error list could not be loaded.");
                        }
                    }
                    else {

                        return apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage + " Error list could not be loaded.");

                    }
                }

            }

            catch (Exception ex)
            {
                return apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage + " Error list could not be loaded.");


            }
        }
コード例 #18
0
        public IActionResult DeleteCommentById(DeleteCommentDTO deleteCommentDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (deleteCommentDTO != null)
                {
                    if (deleteCommentDTO.ModifiedUserId != null)
                    {
                        using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                        {
                            try
                            {
                                var comment = context.Comments.Where(x => x.ID == deleteCommentDTO.Id && x.IsDeleted == false).FirstOrDefault();
                                comment.IsDeleted      = true;
                                comment.ModifiedDate   = DateTime.Now;
                                comment.ModifiedUserId = deleteCommentDTO.ModifiedUserId;
                            }
                            catch
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.CommentNotFound));
                            }
                            context.SaveChanges();
                            return(apiJsonResponse.ApiOkContentResult(deleteCommentDTO));
                        }
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ModifiedUserIdRequired));
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #19
0
        public IActionResult CheckUserOnLogin(LoginDTO loginDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    var user = context.User.FirstOrDefault(x => x.Username == loginDTO.Username || x.Email == loginDTO.Email);
                    if (user == null)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                    }
                    if (user.IsDeleted == true)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                    }
                    if (loginDTO.Password == string.Empty || loginDTO.Password == null)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.PasswordRequired));
                    }
                    if (HelperFunctions.ComputeSha256Hash(loginDTO.Password) == user.Password)
                    {
                        loginDTO.IsAdmin     = user.IsAdmin;
                        loginDTO.IsModerator = user.IsModerator;
                        loginDTO.Email       = user.Email;
                        loginDTO.Username    = user.Username;
                        return(apiJsonResponse.ApiOkContentResult(loginDTO));
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UsernameOrPasswordWrong));
                    }
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #20
0
        public IActionResult SetModeratorByUsername(UserDTO userDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    var user = context.User.FirstOrDefault(x => x.Username == userDTO.Username && x.IsDeleted == false);

                    if (user == null)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                    }
                    else
                    {
                        user.IsModerator = true;
                        user.IsAdmin     = false;

                        if (userDTO.ModifiedUserId != null)
                        {
                            user.ModifiedUserId = userDTO.ModifiedUserId;
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ModifiedUserIdRequired));
                        }
                        user.ModifiedDate = DateTime.Now;

                        context.SaveChanges();

                        return(apiJsonResponse.ApiOkContentResult(Mapper.Map <ModeratorDTO>(user)));
                    }
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #21
0
        public IActionResult DeleteProduct(string BarcodeId)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (BarcodeId != string.Empty)
                    {
                        var product  = context.Products.Where(x => x.BarcodeId == BarcodeId && x.IsDeleted == false).FirstOrDefault();
                        var contents = context.ProductContents.Where(x => x.Product.BarcodeId == BarcodeId && x.IsDeleted == false).ToList();
                        if (contents != null)
                        {
                            foreach (var item in contents)
                            {
                                item.IsDeleted = true;
                            }
                        }
                        if (product != null)
                        {
                            product.IsDeleted = true;
                        }

                        context.SaveChanges();
                        return(apiJsonResponse.ApiOkContentResult(BarcodeId));
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodIdRequired));
                    }
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #22
0
        public IActionResult GetLanguageListOfProductByBarcodeId(BarcodeDTO barcodeDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (barcodeDTO != null)
                {
                    using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                    {
                        var languageList = context.ProductContents.Where(x => x.Product.BarcodeId == barcodeDTO.BarcodeId && x.IsDeleted == false)
                                           .Include(x => x.Language).ToList();
                        List <LanguageDTO> languageDTO = new List <LanguageDTO>();
                        if (languageList != null)
                        {
                            foreach (var item in languageList)
                            {
                                languageDTO.Add(Mapper.Map <LanguageDTO>(item.Language));
                                var l = languageDTO;
                            }
                            return(apiJsonResponse.ApiOkContentResult(languageDTO));
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.NoLanguageFound));
                        }
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodIdRequired));
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #23
0
        public IActionResult GetLanguageList()
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    var languages = context.Languages.Where(x => x.IsDeleted == false).ToList();
                    if (languages != null && languages.Count != 0)
                    {
                        List <LanguageDTO> languageDTOs = new List <LanguageDTO>();

                        foreach (var item in languages)
                        {
                            languageDTOs.Add(Mapper.Map <LanguageDTO>(item));
                        }
                        if (languageDTOs != null)
                        {
                            return(apiJsonResponse.ApiOkContentResult(languageDTOs));
                        }
                        else
                        {
                            return(BadRequest(new ApiBadRequestWithMessage(PublicConstants.NoLanguageFound)));
                        }
                    }
                    else
                    {
                        return(BadRequest(new ApiBadRequestWithMessage(PublicConstants.NoLanguageFound)));
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)));
            }
        }
コード例 #24
0
        public IActionResult UpdateNameAndSurname(UpdateNameAndSurnameDTO updateNameAndSurnameDTO)
        {
            var apiJsonResult = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (context.User.Any(x => x.Username == updateNameAndSurnameDTO.Username && x.IsDeleted == false))
                    {
                        var User = context.User.FirstOrDefault(x => x.Username == updateNameAndSurnameDTO.Username && x.IsDeleted == false);

                        if (updateNameAndSurnameDTO.NewName != string.Empty)
                        {
                            User.Name         = updateNameAndSurnameDTO.NewName;
                            User.ModifiedDate = DateTime.Now;
                        }
                        if (updateNameAndSurnameDTO.NewSurname != string.Empty)
                        {
                            User.Surname      = updateNameAndSurnameDTO.NewSurname;
                            User.ModifiedDate = DateTime.Now;
                        }
                        context.SaveChanges();
                        return(apiJsonResult.ApiOkContentResult(updateNameAndSurnameDTO));
                    }
                    else
                    {
                        return(apiJsonResult.ApiBadRequestWithMessage(PublicConstants.UserNotFoundError));
                    }
                }
            }
            catch
            {
                return(apiJsonResult.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #25
0
        public IActionResult DeleteContent(LanguageAndProductDTO languageAndProductDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    var product = context.ProductContents.Where(x => x.Product.BarcodeId == languageAndProductDTO.BarcodeId && x.Language.LanguageCode == languageAndProductDTO.LanguageCode && x.IsDeleted == false).FirstOrDefault();
                    if (product == null)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductDoesNotFound));
                    }
                    product.IsDeleted = true;

                    context.SaveChanges();
                    return(apiJsonResponse.ApiOkContentResult(languageAndProductDTO));
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #26
0
        public IActionResult CreateProduct(ProductDTO productDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (productDTO != null)
                    {
                        if (productDTO.BarcodeId == string.Empty && productDTO.ProductName == string.Empty)

                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                        }
                        else
                        {
                            if (!context.Products.Any(x => x.BarcodeId == productDTO.BarcodeId && x.IsDeleted == false))
                            {
                                var product = new Product();

                                //product.BarcodeId = productDTO.BarcodeId;
                                //product.ProductName = productDTO.ProductName;
                                //product.ProductCategory = productDTO.ProductCategory;
                                //product.CreatedUserId = productDTO.CreatedUserId;



                                product = Mapper.Map <Product>(productDTO);
                                if (productDTO.FirstImage != null)
                                {
                                    product.FirstImage = productDTO.FirstImage;
                                }
                                else
                                {
                                    product.FirstImage = null;
                                }
                                if (productDTO.SecondImage != null)
                                {
                                    product.SecondImage = productDTO.SecondImage;
                                }
                                else
                                {
                                    product.SecondImage = null;
                                }
                                if (productDTO.ThirdImage != null)
                                {
                                    product.ThirdImage = productDTO.ThirdImage;
                                }
                                else
                                {
                                    product.ThirdImage = null;
                                }
                                if (!context.ProductCategories.Any(x => x.ID == productDTO.ProductCategory.ID && x.IsDeleted == false))
                                {
                                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.NoCategoryFound));
                                }
                                product.ProductCategory = context.ProductCategories.Where(x => x.ID == productDTO.ProductCategory.ID && x.IsDeleted == false).FirstOrDefault();

                                context.Add(product);
                                context.SaveChanges();
                                return(apiJsonResponse.ApiOkContentResult(productDTO));
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                            }
                        }
                    }

                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                    }
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));

                throw;
            }
        }
コード例 #27
0
        public IActionResult GetProductContentByLanguageCode(LanguageAndProductDTO languageAndProductDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (languageAndProductDTO.LanguageCode != null)
                    {
                        if (context.Products.Any(x => x.BarcodeId == languageAndProductDTO.BarcodeId))
                        {
                            if (context.ProductContents.Any(x => x.Language.LanguageCode == languageAndProductDTO.LanguageCode && x.IsDeleted == false && x.Product.BarcodeId == languageAndProductDTO.BarcodeId))
                            {
                                var product = context.ProductContents.Where(x => x.Product.BarcodeId == languageAndProductDTO.BarcodeId &&
                                                                            x.Language.LanguageCode == languageAndProductDTO.LanguageCode &&
                                                                            x.IsDeleted == false)
                                              .Include(m => m.NutritionFact)
                                              .Include(m => m.Product).FirstOrDefault();
                                ContentDTO contentDTO = Mapper.Map <ContentDTO>(product);
                                try
                                {
                                    var comments = context.Comments.Where(x => x.ProductContent.ID == product.ID && x.IsDeleted == false).ToList();

                                    if (comments != null)
                                    {
                                        List <CommentDTO> commentDTOs = new List <CommentDTO>();
                                        // contentDTO.Comments = Mapper.Map<List<CommentDTO>>(comments);
                                        int i = 0;
                                        foreach (var item in comments)
                                        {
                                            var commentDTO = new CommentDTO();
                                            var temp       = context.User.Where(x => x.ID == item.CreatedUserId).FirstOrDefault();
                                            commentDTO.CreatedDate      = item.CreatedDate;
                                            commentDTO.CreatedUserId    = item.CreatedUserId;
                                            commentDTO.Name             = temp.Name;
                                            commentDTO.Surname          = temp.Surname;
                                            commentDTO.Username         = temp.Username;
                                            commentDTO.UserComment      = item.UserComment;
                                            commentDTO.ProductContentId = item.ProductContent.ID;
                                            commentDTO.ModifiedDate     = item.ModifiedDate;
                                            commentDTO.ModifiedUserId   = item.ModifiedUserId;



                                            commentDTOs.Add(commentDTO);
                                        }

                                        contentDTO.Comments = commentDTOs;
                                    }
                                }
                                catch
                                {
                                }


                                int totalVotes = context.Votes.Count(x => x.Product.BarcodeId == languageAndProductDTO.BarcodeId);
                                if (totalVotes == 0)
                                {
                                    contentDTO.AverageVote = 5.0M;
                                }
                                else
                                {
                                    int count = 0;
                                    foreach (var item in context.Votes.Where(x => x.Product.BarcodeId == languageAndProductDTO.BarcodeId))
                                    {
                                        if (item.UserVote != null)
                                        {
                                            count += (int)item.UserVote;
                                        }
                                    }
                                    if (count != 0)
                                    {
                                        contentDTO.AverageVote = decimal.Round((count / (decimal)totalVotes), 2);
                                    }
                                    else
                                    {
                                        contentDTO.AverageVote = 5.0M;
                                    }
                                }


                                return(apiJsonResponse.ApiOkContentResult(contentDTO));
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodeIdOrLanguageCodeDoesNotFound));
                            }
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProductDoesNotFound));
                        }
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideLanguageCode));
                    }
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #28
0
        public IActionResult CreateContentOfProduct(ContentDTO contentDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (contentDTO != null)
                    {
                        if (contentDTO.Product.BarcodeId != null)
                        {
                            if (contentDTO.CreatedUserId != null)
                            {
                                using (var transaction = context.Database.BeginTransaction())
                                {
                                    if (context.Products.Any(x => x.BarcodeId == contentDTO.Product.BarcodeId && x.IsDeleted == false))
                                    {
                                        contentDTO.Product.ID = context.Products.FirstOrDefault(x => x.BarcodeId == contentDTO.Product.BarcodeId && x.IsDeleted == false).ID;
                                    }

                                    else
                                    {
                                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodIdRequired));
                                    }
                                    if (context.Languages.Any(x => x.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false))
                                    {
                                        contentDTO.Language.ID = context.Languages.FirstOrDefault(x => x.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false).ID;
                                    }
                                    else

                                    {
                                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideLanguageCode));
                                    }
                                    if (context.ProductContents.Any(x => x.Product.ID == contentDTO.Product.ID && x.IsDeleted == false && x.Language.ID == contentDTO.Language.ID))
                                    {
                                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ExistingContentForProduct));
                                    }
                                    // contentDTO.NutritionFact.ID = context.NutritionFacts.FirstOrDefault(x => x.ID == contentDTO.NutritionFact.ID && x.IsDeleted == false).ID;

                                    var nutritionFacts = new NutritionFacts();

                                    nutritionFacts               = Mapper.Map <NutritionFacts>(contentDTO.NutritionFact);
                                    nutritionFacts.BarcodeId     = contentDTO.Product.BarcodeId;
                                    nutritionFacts.CreatedUserId = contentDTO.CreatedUserId;
                                    nutritionFacts.LanguageCode  = contentDTO.Language.LanguageCode;

                                    context.Add(nutritionFacts);
                                    context.SaveChanges();
                                    contentDTO.NutritionFact.ID = context.NutritionFacts.Where(x => x.BarcodeId == contentDTO.Product.BarcodeId && x.LanguageCode == contentDTO.Language.LanguageCode && x.IsDeleted == false).FirstOrDefault().ID;

                                    var content = context.ProductContents.Add(Mapper.Map <ProductContent>(contentDTO));

                                    context.SaveChanges();



                                    transaction.Commit();
                                    return(apiJsonResponse.ApiOkContentResult(Mapper.Map <ProductContent>(contentDTO)));
                                }
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.ProvideACreatedUserId));
                            }
                        }
                        else
                        {
                            return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodIdRequired));
                        }
                    }
                    else
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                    }
                }
            }
            catch (Exception ex)
            {
                { return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage)); }
            }
        }
コード例 #29
0
        public IActionResult GetLanguageListOfProductByBarcodeId2(BarcodeDTO barcodeDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                if (barcodeDTO != null)
                {
                    using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                    {
                        var groupID = context.Products.Where(x => x.BarcodeId == barcodeDTO.BarcodeId && x.IsDeleted == false).FirstOrDefault().ProductGroupId;
                        if (groupID != 0 && groupID != null)
                        {
                            var productList = context.Products.Where(x => x.ProductGroupId == groupID && x.IsDeleted == false).ToList();
                            List <ProductContent> languageList = new List <ProductContent>();
                            foreach (var item in productList)
                            {
                                ProductContent language = new ProductContent();

                                language = context.ProductContents.Where(x => x.Product.BarcodeId == item.BarcodeId && x.IsDeleted == false).
                                           Include(x => x.Language).FirstOrDefault();
                                languageList.Add(language);
                            }
                            List <ProductAndLanguageListDTO> languageDTO = new List <ProductAndLanguageListDTO>();
                            if (languageList != null)
                            {
                                foreach (var item in languageList)
                                {
                                    ProductAndLanguageListDTO language = new ProductAndLanguageListDTO();
                                    language.BarcodeId          = item.Product.BarcodeId;
                                    language.ID                 = item.Language.ID;
                                    language.LanguageCode       = item.Language.LanguageCode;
                                    language.LanguageName       = item.Language.LanguageName;
                                    language.NativeLanguageName = item.Language.NativeLanguageName;
                                    if (!languageDTO.Any(x => x.LanguageCode == language.LanguageCode))
                                    {
                                        languageDTO.Add(language);
                                    }
                                    // languageDTO.Add(Mapper.Map<LanguageDTO>(item.Language));

                                    var l = languageDTO;
                                }
                                return(apiJsonResponse.ApiOkContentResult(languageDTO));
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
                            }
                        }
                        else
                        {
                            var languageList = context.ProductContents.Where(x => x.Product.BarcodeId == barcodeDTO.BarcodeId && x.IsDeleted == false)
                                               .Include(x => x.Language).ToList();
                            List <LanguageDTO> languageDTO = new List <LanguageDTO>();
                            if (languageList != null)
                            {
                                foreach (var item in languageList)
                                {
                                    languageDTO.Add(Mapper.Map <LanguageDTO>(item.Language));
                                    var l = languageDTO;
                                }
                                return(apiJsonResponse.ApiOkContentResult(languageDTO));
                            }
                            else
                            {
                                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.NoLanguageFound));
                            }
                        }
                    }
                }
                else
                {
                    return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.BarcodIdRequired));
                }
            }
            catch
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }
        }
コード例 #30
0
        public IActionResult CreateUser(UserDTO userDTO)
        {
            var apiJsonResponse = new ApiJsonResponse();

            try
            {
                using (FoodInfoServiceContext context = new FoodInfoServiceContext())
                {
                    if (context.User.Any(m => m.Email == userDTO.Email || m.Username == userDTO.Username))
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.UserNameOrEmailAlreadyExistError));
                    }
                    if (userDTO.Username == string.Empty)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage("Username is required"));
                    }
                    if (userDTO.Email == string.Empty)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage("Email is required"));
                    }
                    if (userDTO.Password == string.Empty)
                    {
                        return(apiJsonResponse.ApiBadRequestWithMessage("Password is required"));
                    }



                    var hashedPassword = HelperFunctions.ComputeSha256Hash(userDTO.Password);
                    userDTO.Password = hashedPassword;
                    var x = context.User.Add(Mapper.Map <User>(userDTO));

                    //if (!ModelState.IsValid)
                    //{
                    //    return BadRequest(new ApiBadRequestResponse(ModelState));
                    //}
                    context.SaveChanges();
                    UserDTO userCredentialsOnSuccess = new UserDTO();
                    userCredentialsOnSuccess.Name     = userDTO.Name;
                    userCredentialsOnSuccess.Surname  = userDTO.Surname;
                    userCredentialsOnSuccess.Username = userDTO.Username;
                    userCredentialsOnSuccess.Email    = userDTO.Email;
                    return(apiJsonResponse.ApiOkContentResult(userCredentialsOnSuccess));
                    //var isExistUsername = foodInfoServiceContext.User.FirstOrDefault(x => x.Username == "Fatihs");


                    //return Ok(new ApiOkResponse(foodInfoServiceContext.User.FirstOrDefault(x => x.Name == "Fatih")));
                }
            }
            catch (Exception ex)
            {
                return(apiJsonResponse.ApiBadRequestWithMessage(PublicConstants.SysErrorMessage));
            }


            //    try
            //    {
            //        if (!ModelState.IsValid)
            //        {
            //            return BadRequest(new ApiBadRequestResponse(ModelState));
            //        }

            //        using (FoodInfoServiceContext foodInfoServiceContext = new FoodInfoServiceContext())
            //        {
            //            var isExistUsername = foodInfoServiceContext.User.FirstOrDefault(x => x.Username == "Fatihs");


            //            return Ok(new ApiOkResponse(foodInfoServiceContext.User.FirstOrDefault(x => x.Name == "Fatih")));

            //        }
            //    }
            //    catch
            //    {
            //        return BadRequest();

            //    }
            //    return BadRequest();
            //}
            //catch
            //{
            //    return Ok();

            //}
            //return BadRequest();
        }