Example #1
0
        public async Task <CommonResponse> ModifyUser(ModifyUserRequest userDetailValues)
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var userCount = await uow.Repository <User>().Query().Select().Where(a => a.Id != userDetailValues.userId && a.UserName == userDetailValues.userName).CountAsync();

                if (userCount > 0)
                {
                    return(CommonResponse.CreateError("Username is already exits", "ERR001", ""));
                }

                var userValues = await uow.Repository <User>().Query().Select().SingleOrDefaultAsync(t => t.Id == userDetailValues.userId);

                if (userValues == null)
                {
                    return(CommonResponse.CreateError("Error", "Err02", "User Not found"));
                }
                userValues.Country      = userDetailValues.country;
                userValues.EmailId      = userDetailValues.emailId;
                userValues.FullName     = userDetailValues.name;
                userValues.UserName     = userDetailValues.userName;
                userValues.UserPassword = userValues.UserPassword;
                userValues.UserRole     = userDetailValues.userRole;
                userValues.City         = userDetailValues.city;

                var response = uow.SaveChanges();
                if (response.Response.status == false)
                {
                    return(CommonResponse.CreateError("Error occured while updating user.", "ERR001", ""));
                }

                return(CommonResponse.CreateSuccess("User updated successfully.", "SUC002", ""));
            }
        }
Example #2
0
        public async Task <CommonResponse> GetUserRoles()
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var userRoles = await uow.Repository <User>().Query().Select().FirstOrDefaultAsync(t => t.UserRole == 2);

                var roles = new List <UserRolesDTO>();
                roles.Add(new UserRolesDTO
                {
                    roleId   = (int)Roles.Admin,
                    roleName = Roles.Admin.ToString()
                });
                roles.Add(new UserRolesDTO
                {
                    roleId   = (int)Roles.Agent,
                    roleName = Roles.Agent.ToString()
                });
                roles.Add(new UserRolesDTO
                {
                    roleId   = (int)Roles.Analyzer,
                    roleName = Roles.Analyzer.ToString()
                });

                if (userRoles != null)
                {
                    roles.Add(new UserRolesDTO
                    {
                        roleId   = (int)Roles.Supplier,
                        roleName = Roles.Supplier.ToString()
                    });
                }

                return(CommonResponse.CreateSuccess("Success", "SUC001", roles));
            }
        }
Example #3
0
        public async Task <CommonResponse> AddUser(AddUserRequest newUserValues)
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var user = await uow.Repository <User>().Query().Select().FirstOrDefaultAsync(a => a.UserName == newUserValues.userName);

                if (user != null)
                {
                    return(CommonResponse.CreateError("Username is already exits.", "ERR001", ""));
                }

                var newUser = new User
                {
                    FullName     = newUserValues.name,
                    Country      = newUserValues.country,
                    EmailId      = newUserValues.emailId,
                    State        = newUserValues.state,
                    PhoneNumber  = newUserValues.phoneNumber,
                    UserPassword = newUserValues.password,
                    UserName     = newUserValues.userName,
                    UserRole     = newUserValues.userRole,
                    City         = newUserValues.city
                };

                uow.Repository <User>().Add(newUser);
                var response = uow.SaveChanges();
                if (response.Response.status == false)
                {
                    return(CommonResponse.CreateError("Error occured while adding user.", "ERR001", ""));
                }

                return(CommonResponse.CreateSuccess("User added successfully.", "SUCC001", ""));
            }
        }
Example #4
0
 public async Task <CommonResponse> GetDealTransactionDetails()
 {
     using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
     {
         var transactionDetails = await(from pTransaction in uow.Repository <ProductTransaction>().Query().Select()
                                        join pAnalyzer in uow.Repository <ProductAnalyzer>().Query().Select()
                                        on pTransaction.ProductAnalyzerId equals pAnalyzer.Id
                                        join pSupplier in uow.Repository <SupplierProduct>().Query().Select()
                                        on pAnalyzer.SupplilerProductId equals pSupplier.ProductId
                                        join user in uow.Repository <User>().Query().Select()
                                        on pSupplier.SupplierId equals user.Id
                                        join product in uow.Repository <Product>().Query().Select()
                                        on pSupplier.ProductId equals product.ProductId
                                        where pTransaction.Deal != null && pTransaction.Deal != ""
                                        select new ProductsTransactionDetailsDTO
         {
             AnalyzedComposition  = pAnalyzer.AnalyzedComposition ?? 0,
             Composition          = pSupplier.Composition ?? 0,
             DealStatus           = pTransaction.Deal,
             ProductName          = product.ProductName,
             ProductTransactionId = pTransaction.Id,
             supplierName         = user.FullName
         }).ToListAsync();
         return(CommonResponse.CreateSuccess("Success", "Suc01", transactionDetails));
     }
 }
Example #5
0
        public async Task <CommonResponse> AddProduct(AddProductRequest productValues, int userId)
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var product = new Product
                {
                    ProductName = productValues.ProductName
                };

                uow.Repository <Product>().Add(product);
                var responseProduct = uow.SaveChanges();
                if (responseProduct.Response.status == false)
                {
                    return(CommonResponse.CreateError("Error occured while adding supplier products.", "ERR001", ""));
                }

                var supplierProduct = new SupplierProduct
                {
                    ProductId       = product.ProductId,
                    Quantity        = productValues.Quantity,
                    Composition     = productValues.Composition,
                    SupplierId      = userId,
                    AvailableStatus = "a"
                };
                uow.Repository <SupplierProduct>().Add(supplierProduct);

                var response = uow.SaveChanges();
                if (response.Response.status == false)
                {
                    return(CommonResponse.CreateError("Error occured while adding supplier products.", "ERR001", ""));
                }

                return(CommonResponse.CreateSuccess("Success", "SUC001", ""));
            }
        }
Example #6
0
        public async Task <CommonResponse> SubmitAnalyzedSample(AnalyserSampleRequest values, int userId)
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var productSupplierEntity = await uow.Repository <SupplierProduct>().Query().Select().SingleOrDefaultAsync(t => t.Id == values.ProductSupplierId);

                if (productSupplierEntity == null)
                {
                    return(CommonResponse.CreateError("Error", "Err02", "Product not found"));
                }

                var productAnalyzer = new ProductAnalyzer
                {
                    AnalyzerId          = userId,
                    SupplilerProductId  = values.ProductSupplierId ?? 1,
                    AnalyzedComposition = values.AnalysedComposition ?? 1,
                    IsDealPlaced        = "y"
                };

                uow.Repository <ProductAnalyzer>().Add(productAnalyzer);
                productSupplierEntity.Composition -= productAnalyzer.AnalyzedComposition;
                var response = uow.SaveChanges();
                if (response.Response.status == false)
                {
                    return(CommonResponse.CreateError("Error occured while adding analysing composition.", "ERR001", ""));
                }

                return(CommonResponse.CreateSuccess("Success", "SUC001", ""));
            }
        }
Example #7
0
        public async Task <CommonResponse> DisableUser(int userId)
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var user = await uow.Repository <User>().Query().Select().SingleOrDefaultAsync(t => t.Id == userId);

                if (user != null)
                {
                    return(CommonResponse.CreateError("Error", "Err02", "Uer not found"));
                }
                uow.Repository <User>().Delete(user);
                return(CommonResponse.CreateSuccess("Success", "Suc01", "User Removed"));
            }
        }
Example #8
0
 public async Task <CommonResponse> DecideTheDeal(MakeDealRequest values)
 {
     using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
     {
         var transactionEntity = new ProductTransaction
         {
             ProductAnalyzerId = values.productAnalyzeId,
             Deal = values.DealStatus
         };
         uow.Repository <ProductTransaction>().Add(transactionEntity);
         uow.SaveChanges();
         return(CommonResponse.CreateSuccess("success", "Suc01", transactionEntity));
     }
 }
Example #9
0
        public async Task <CommonResponse> Login(LoginRequest requestValues)
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var tokenResponse = await this.tokenService.GenerateToken(requestValues.UserName, requestValues.Password);

                if (tokenResponse.ToLower().Contains("error"))
                {
                    return(CommonResponse.CreateError("Invalid user credentials, please try again.", "ERR001", ""));
                }
                dynamic newToken   = Newtonsoft.Json.JsonConvert.DeserializeObject(tokenResponse);
                string  tokenValue = "Bearer " + newToken.access_token;

                LoginResponse loginResponse = new LoginResponse();
                loginResponse.token        = tokenValue;
                loginResponse.UserFullName = newToken.FullName;
                return(CommonResponse.CreateSuccess("Logged in successfully.", "SUC001", loginResponse));
            }
        }
Example #10
0
        public async Task <CommonResponse> GetUserDetails(int userId)
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var userDetails = await uow.Repository <User>().Query().Select().Where(t => t.Id == userId).Select(j => new UserDetail
                {
                    country     = j.Country,
                    emailId     = j.EmailId,
                    name        = j.FullName,
                    phoneNumber = j.PhoneNumber,
                    state       = j.State,
                    userName    = j.UserName,
                    userId      = j.Id,
                    city        = j.City
                }).SingleOrDefaultAsync();

                return(CommonResponse.CreateSuccess("success", "Suc01", userDetails));
            }
        }
Example #11
0
        public async Task <CommonResponse> GetAllSuppliers()
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var suppliers = await uow.Repository <User>().Query().Select().Where(t => t.UserRole == (int)Roles.Supplier).Select(j => new UserDetail
                {
                    country     = j.Country,
                    emailId     = j.EmailId,
                    name        = j.FullName,
                    phoneNumber = j.PhoneNumber,
                    state       = j.State,
                    userName    = j.UserName,
                    userId      = j.Id,
                    city        = j.City
                }).ToListAsync();

                return(CommonResponse.CreateSuccess("success", "Suc01", suppliers));
            }
        }
Example #12
0
        public async Task <CommonResponse> GetProducts()
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var products = await(from product in uow.Repository <Product>().Query().Select()
                                     join supplierProduct in uow.Repository <SupplierProduct>().Query().Select()
                                     on product.ProductId equals supplierProduct.ProductId
                                     where supplierProduct.AvailableStatus.ToLower() == "a"
                                     select new SupplierProductsDTO
                {
                    Composition       = supplierProduct.Composition ?? 0,
                    ProductName       = product.ProductName,
                    Quantity          = supplierProduct.Quantity ?? 0,
                    SupplierProductId = supplierProduct.Id
                }).ToListAsync();

                return(CommonResponse.CreateSuccess("Success", "Suc01", products));
            }
        }
Example #13
0
        public async Task <CommonResponse> GetUsers()
        {
            using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
            {
                var users = await uow.Repository <User>().Query().Select(j => new UserDetail
                {
                    country      = j.Country,
                    emailId      = j.EmailId,
                    name         = j.FullName,
                    phoneNumber  = j.PhoneNumber,
                    state        = j.State,
                    userName     = j.UserName,
                    userId       = j.Id,
                    city         = j.City,
                    userRole     = j.UserRole,
                    userRoleName = j.Role.RoleName
                }).ToListAsync();

                return(CommonResponse.CreateSuccess("Success", "SUC001", users));
            }
        }
Example #14
0
 public async Task <CommonResponse> DealDetails()
 {
     using (var uow = this.unitOfWorkFactory.GetUnitOfWork())
     {
         var dealDetails = await(from user in uow.Repository <User>().Query().Select()
                                 join sproduct in uow.Repository <SupplierProduct>().Query().Select()
                                 on user.Id equals sproduct.SupplierId
                                 join product in uow.Repository <Product>().Query().Select()
                                 on sproduct.ProductId equals product.ProductId
                                 join panalyzer in uow.Repository <ProductAnalyzer>().Query().Select()
                                 on sproduct.Id equals panalyzer.SupplilerProductId
                                 select new DealsDetailsDTO
         {
             AnalyzedComposition = panalyzer.AnalyzedComposition ?? 0,
             Composition         = sproduct.Composition ?? 0,
             ProductAnalyzerId   = panalyzer.Id,
             ProductName         = product.ProductName,
             Quantity            = sproduct.Quantity ?? 0,
             SupplierName        = user.FullName
         }).ToListAsync();
         return(CommonResponse.CreateSuccess("success", "Suc01", dealDetails));
     }
 }
Example #15
0
        public CommonResponse SaveChanges()
        {
            try
            {
                this.context.SaveChanges();
                return(CommonResponse.CreateSuccess("SaveChanges", "SUC001", ""));
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                return(CommonResponse.CreateError("SaveChanges", "ERR0001", ex.Message));
            }

            catch (DbUpdateConcurrencyException ex)
            {
                return(CommonResponse.CreateError("SaveChanges", "ERR0001", ex.Message));
            }

            catch (DbUpdateException ex)
            {
                return(CommonResponse.CreateError("SaveChanges", "ERR0001", ex.Message));
            }
            catch (Exception ex)
            {
                return(CommonResponse.CreateError("SaveChanges", "ERR0001", ex.Message));
            }
        }