/// <summary> /// This method will accept the Product details and save it into the database. /// </summary> /// <param name="objProduct">Object containing the details of Product</param> /// <returns>Returns the same Object</returns> public ResultStatus SaveProduct(ProductVm objProduct) { if (!IsProductExist(objProduct)) { try { using (Data.Model.LicenseManagementMVCEntities DbContext = new LicenseManagementMVCEntities()) { try { Data.Model.Product objProductData = new Data.Model.Product(); objProductData.ProductName = objProduct.ProductName; DbContext.Products.Add(objProductData); DbContext.SaveChanges(); } catch (Exception) { return(ResultStatus.QueryNotExecuted); } } } catch (Exception) { return(ResultStatus.ConnectionError); } } else { return(ResultStatus.AlreadyExist); } return(ResultStatus.Success); }
public ServiceResponse <Data.Model.Product> CreateProduct(Data.Model.Product product) { try { dbContext.Products.AddAsync(product); var newInventory = new ProductInventory { Product = product, QuantityOnHand = 0, IdealQuantity = 10, }; dbContext.ProductInventories.AddAsync(newInventory); dbContext.SaveChangesAsync(); return(new ServiceResponse <Data.Model.Product> { Data = product, Time = DateTime.UtcNow, Message = "Saved new product", isSuccess = true, }); } catch (System.Exception) { return(new ServiceResponse <Data.Model.Product> { Data = null, Time = DateTime.UtcNow, Message = "Error while saving new product", isSuccess = false, }); } }
public static ProductModel SerializeProductModel(Data.Model.Product product) { return(new ProductModel { Id = product.Id, CreateOn = product.CreateOn, UpdateOn = product.UpdateOn, Price = product.Price, Name = product.Name, Description = product.Description, IsTaxable = product.IsTaxable, IsArchived = product.IsArchived, }); }
/// <summary> /// This class will accepts the object holding ProductId and displays all the software of that product in box format. /// </summary> /// <param name="objProductRequest">Object holding ProductId of selected product</param> /// <returns>Software object having all the software of selected product with their specific details</returns> public List <BusinessEntities.Software> ShowSoftware(BusinessEntities.Product objProductRequest) { using (Data.Model.LicenseManagementMVCEntities DbContext = new LicenseManagementMVCEntities()) { Data.Model.Product objProductDataRequest = new Data.Model.Product(); objProductDataRequest.ProductId = objProductRequest.ProductId; List <BusinessEntities.Software> softwareList = new List <BusinessEntities.Software>(); List <Data.Model.Software> softwareListData = new List <Data.Model.Software>(); softwareListData = DbContext.Softwares.ToList(); var result = from s in DbContext.Softwares join p in DbContext.Products on s.ProductId equals p.ProductId select new { ProductName = p.ProductName, SoftwareName = s.SoftwareName, SoftwareId = s.SoftwareId, ProductId = p.ProductId, SoftwareTypeId = s.SoftwareTypeId }; BusinessEntities.Software objSoftware = new BusinessEntities.Software(); BusinessEntities.Product objProduct = new BusinessEntities.Product(); if (objProductRequest.ProductId != -1) { result = result.Where(s => s.ProductId == objProductRequest.ProductId); } foreach (var s in result) { objSoftware = new BusinessEntities.Software(); objSoftware.SoftwareId = s.SoftwareId; objSoftware.SoftwareName = s.SoftwareName; objProduct = new BusinessEntities.Product(); objProduct.ProductId = s.ProductId; objProduct.ProductName = s.ProductName; objSoftware.Product = objProduct; softwareList.Add(objSoftware); } return(softwareList); } }
private static void InitializeDatabase() { var exampleUser = new Data.Model.User { FirstName = "Onur", LastName = "Kayabasi", Email = "*****@*****.**", HashedPassword = Infrastructure.Service.EncryptionHelper.CreateHashed("testparola123"), Role = Infrastructure.Service.Constants.JwtAuthenticationService.UserRole.Admin }; Data.Utility.Initializer.ecommerceDb.InitializeRepository <Data.Model.User>(new List <Data.Model.User> { exampleUser }); var laptopCategory = new Data.Model.Category { Name = "Laptop" }; Data.Utility.Initializer.ecommerceDb.InitializeRepository <Data.Model.Category>(new List <Data.Model.Category> { laptopCategory }); var msiProduct = new Data.Model.Product { Name = "MSI GP62 7RD", Description = "Description of MSI GP62 7RD", Price = 7000, Category = laptopCategory }; Data.Utility.Initializer.ecommerceDb.InitializeRepository <Data.Model.Product>(new List <Data.Model.Product> { msiProduct }); var exampleBasket = new Data.Model.Basket { Products = new List <Data.Model.Product> { msiProduct } }; Data.Utility.Initializer.ecommerceDb.InitializeRepository <Data.Model.Basket>(new List <Data.Model.Basket> { exampleBasket }); var exampleAddress = new Data.Model.Address { Country = "Turkey", City = "Istanbul", District = "Pendik", Zip = 34909 }; Data.Utility.Initializer.ecommerceDb.InitializeRepository <Data.Model.Address>(new List <Data.Model.Address> { exampleAddress }); Data.Utility.Initializer.ecommerceDb.InitializeRepository <Data.Model.Order>(new List <Data.Model.Order> { new Data.Model.Order { Owner = exampleUser, Basket = exampleBasket, Address = exampleAddress, } }); }