Ejemplo n.º 1
0
        public async Task <List <Cart> > AddCartAsync(InvoiceCartViewModel invoiceCart, int id)
        {
            try
            {
                //store invoice full_cost
                //Double fullcost = 0;

                for (int i = 0; i < invoiceCart.listcart.Count; i++)
                {
                    //assign every item in the invoice with it's invoice_id
                    invoiceCart.listcart[i].InvoiceId = id;

                    //fullcost += Convert.ToDouble(invoiceCart.listcart[i].Price);

                    await _yamamadbContext.Cart.AddAsync(invoiceCart.listcart[i]);

                    await _yamamadbContext.SaveChangesAsync();

                    var store = _yamamadbContext.Store.Where(x => x.ProId == invoiceCart.listcart[i].ProductId).SingleOrDefault();
                    if (invoiceCart.invoice.Type == "Purchses" || invoiceCart.invoice.Type == "import")
                    {
                        if (store != null)
                        {
                            store.Quantity += invoiceCart.listcart[i].Qty;
                            _yamamadbContext.Store.Update(store);
                            _yamamadbContext.SaveChanges();
                        }
                        else
                        {
                            Store newStore = new Store
                            {
                                ProId    = invoiceCart.listcart[i].ProductId,
                                Quantity = invoiceCart.listcart[i].Qty,
                                Name     = _yamamadbContext.Product.Where(x => x.Idproduct == invoiceCart.listcart[i].ProductId).Select(x => x.Name).SingleOrDefault()
                            };
                            _yamamadbContext.Store.Add(store);
                            _yamamadbContext.SaveChanges();
                        }
                    }
                    else if (invoiceCart.invoice.Type == "sell" || invoiceCart.invoice.Type == "export")
                    {
                        if (store != null)
                        {
                            store.Quantity -= invoiceCart.listcart[i].Qty;
                            _yamamadbContext.Store.Update(store);
                            _yamamadbContext.SaveChanges();
                        }
                    }
                }
                return(invoiceCart.listcart);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        // function to add new project
        public async Task <int> AddProjectAsync(Project project)
        {
            int result = 0;
            // add new project
            await _db.Project.AddAsync(project);

            await _db.SaveChangesAsync();

            //if the operation succecced return 1
            result += 1;
            return(result);
        }
Ejemplo n.º 3
0
        public async Task <int> AddTarget(Target target)
        {
            if (_db != null)
            {
                await _db.Target.AddAsync(target);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 4
0
        public async Task <int> AddAlert(Alert taskTypeViewModel)
        {
            if (_db != null)
            {
                await _db.Alert.AddAsync(taskTypeViewModel);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 5
0
        public async Task <int> AddRequestInfo(TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                await _db.RequestInformation.AddAsync(taskTypeViewModel.reqInfo);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 6
0
        // function to add new factory
        public async Task <int> AddFactoryAsync(Factory factory)
        {
            int result = 0;
            // add new factory
            await _db.Factory.AddAsync(factory);

            await _db.SaveChangesAsync();

            //if the operation succecced return 1
            result += 1;
            return(result);
        }
Ejemplo n.º 7
0
        //Adding new Visit
        public async Task <int> AddVisit(TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                await _db.Visit.AddAsync(taskTypeViewModel.visit);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 8
0
        public async Task <int> AddProduction(Production prod)
        {
            if (_db != null)
            {
                await _db.Production.AddAsync(prod);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 9
0
        /*  this finction will recieve product id as parameter and get the current quantity for this product in
         * the store and  create a new object from balance class and fill the last period and first period with
         * this quantity and  let the date of last period as the current date
         * and the date of first is the first day of the next month and the product id is the passed parameter*/
        public async Task <Double> AddBalanceAsync(string name)
        {
            int prodid = _db.Product.Where(x => x.Name == name).Select(x => x.Idproduct).FirstOrDefault();

            //get quantity of this product in store
            var qty = _db.Store.Where(s => s.ProId == prodid).Select(s => s.Quantity).FirstOrDefault();
            //get the current date
            var dateandtime = DateTime.Now;
            var date        = dateandtime.Date;
            //create a new object from balance class
            Balance newbalance = new Balance
            {
                ProductId1  = prodid,
                FirstPeriod = qty,
                LastPeriod  = qty,
                DateOfFirst = date.AddMonths(1).AddDays(-date.Day + 1),
                DateOfLast  = date,
            };
            //add the balance record to database
            await _db.Balance.AddAsync(newbalance);

            //save changes
            await _db.SaveChangesAsync();

            return(qty);
        }
Ejemplo n.º 10
0
        // add a new production
        // we use the (StoreViewModel) view model because we will need data from  more than one table
        public async Task <int> AddProductionAsync(Production production)
        {
            // declare a variable
            int result = 0;
            // add the new production object to database
            await _db.Production.AddAsync(production);

            //commit the changes into database
            await _db.SaveChangesAsync();

            //get the added production and store it in variable
            var RecentProduction = _db.Production.OrderByDescending(p => p.Idproduction).FirstOrDefault();
            // get the product id from this added  production from the RecentProduction variable
            int?id = RecentProduction.IdProduct;

            //get the quantity from the added production  from the RecentProduction variable
            int qty = RecentProduction.Quantity.Value;

            // creat a loop to pass the store records and update the product quantity according to the product id
            foreach (var item in _db.Store)
            {
                if (item.ProId == id)
                {
                    item.Quantity += qty;
                }
            }
            //commit the changes into database
            _db.SaveChanges();
            //if the operation succecced return 1
            result += 1;
            //};

            return(result);
        }
Ejemplo n.º 11
0
        // add new  import invoice (this operation will affect on store quantity where the quantity in the store for specific product will increase with every added invoice)
        public async Task <Invoice> AddImportInvoceAsync(InvoiceCartViewModel impoInvoice)
        {
            try
            {
                if (impoInvoice.invoice.Paid < impoInvoice.invoice.FullCost)
                {
                    impoInvoice.invoice.RemainForYamama = impoInvoice.invoice.FullCost - impoInvoice.invoice.Paid;
                }
                else if (impoInvoice.invoice.Paid > impoInvoice.invoice.FullCost)
                {
                    impoInvoice.invoice.RemainForCustomer = impoInvoice.invoice.Paid - impoInvoice.invoice.FullCost;
                }
                else
                {
                    impoInvoice.invoice.RemainForCustomer = impoInvoice.invoice.RemainForYamama = 0;
                }

                // if one of the previous conditions is true then save the invoice in the database
                await _db.Invoice.AddAsync(impoInvoice.invoice);

                //commit the changes
                await _db.SaveChangesAsync();

                //get id for this invoice

                var RecentInvoice = _db.Invoice.OrderByDescending(p => p.Idinvoice).FirstOrDefault();

                int RecentInvoiceID = RecentInvoice.Idinvoice;
                //add cart for this invoice
                await _cart.AddCartAsync(impoInvoice, RecentInvoiceID);

                _db.SaveChanges();
                //get the last addes cart
                var RecentCart = _db.Cart.OrderByDescending(c => c.IdCart).FirstOrDefault();
                //get the quantity from this cart
                Double qty = RecentCart.Qty;
                //get the product id from this cart
                int?id = RecentCart.ProductId;

                //pass the store records and add the quantity for the specific product id
                foreach (var item in _db.Store)
                {
                    if (item.ProId == id)
                    {
                        item.Quantity += qty;
                    }
                }
                //commit changes
                _db.SaveChanges();

                return(impoInvoice.invoice);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
        public async Task <Double> AddQuestionnaire(QuestionnaireViewModel questionnaireViewModel)
        {
            List <QA> qa = questionnaireViewModel.QA;
            //store sum of answers_weights
            Double sum = 0;

            for (int i = 0; i < qa.Count; i++)
            {
                int question = qa[i].QID;
                int answer   = qa[i].AID;
                int weight   = _yamamadbcontext.Answers.Where(x => x.Idanswers == answer).Select(x => x.AnswerWeight).SingleOrDefault();
                sum += weight;
            }
            double avg = sum / (qa.Count);

            //if (questionnaireViewModel.Factory != 0) { client = questionnaireViewModel.Factory; } else { client = questionnaireViewModel.Project; }

            CustomerSatisfactionReports reports = new CustomerSatisfactionReports
            {
                ProjectId = (questionnaireViewModel.ProjectId != 0) ? questionnaireViewModel.ProjectId : (int?)null,

                FactoryId = (questionnaireViewModel.FactoryId != 0) ? questionnaireViewModel.FactoryId : (int?)null,


                Notes = questionnaireViewModel.Notes,
                SatisfactionEvaluation = avg
            };
            await _yamamadbcontext.CustomerSatisfactionReports.AddAsync(reports);

            await _yamamadbcontext.SaveChangesAsync();

            //get id for this report

            var RecentReport   = _yamamadbcontext.CustomerSatisfactionReports.OrderByDescending(p => p.IdcustomerSatisfactionReports).FirstOrDefault();
            int RecentReportID = RecentReport.IdcustomerSatisfactionReports;

            //assign every report with its questions and answers
            await AddToLink_R_Q_A(qa, RecentReportID);


            return(0);
        }
Ejemplo n.º 13
0
        public async Task <int> DeleteInvoiceAsync(int IdInvoice)
        {
            int result = 0;
            //Find the invoice for specific id
            var invoice = await _yamamadbContext.Invoice.FirstOrDefaultAsync(x => x.Idinvoice == IdInvoice);

            if (invoice != null)
            {
                //Delete that invoice

                _yamamadbContext.Invoice.Remove(invoice);

                //Commit the transaction
                await _yamamadbContext.SaveChangesAsync();

                result += 1;
                return(result);
            }
            return(result);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> addphoto(ImageViewModel model)
        {
            try
            {
                //check if the sent model not null
                if (ModelState.IsValid)
                {
                    // declare a variable
                    string fileName = null;

                    //check if the sent model has a photo
                    if (model.photo != null)
                    {
                        //declare a variable and stor in it the path of the uploaded files and photos
                        string uploading = Path.Combine(_env.WebRootPath, "Upload");

                        //give the uploaded file a unique name

                        fileName = Guid.NewGuid().ToString() + "_" + model.photo.FileName;

                        // declare a variable and store in it the name of file and the path
                        string filePath = Path.Combine(uploading, fileName);

                        model.photo.CopyTo(new FileStream(filePath, FileMode.Create));
                    }
                    //create a new object from photo class
                    Photo newphoto = new Photo
                    {
                        Path      = fileName,
                        ProjectId = model.ProjectId,
                        //Name = model.Name,
                    };

                    // add the new photo object to the database
                    await _photo.AddPhotoAsync(newphoto);

                    //save the changes
                    await _db.SaveChangesAsync();

                    var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", newphoto);
                    return(Ok(Response));
                }

                return(null);
            }

            catch (Exception)
            {
                var Response = new ResponseViewModel(false, HttpStatusCode.NoContent, "failed", null);
                return(Ok(Response));
            }
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> Add(Store store)
        {
            try
            {
                await _store.AddstoreAsync(store);

                await _db.SaveChangesAsync();

                var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", store);
                return(Ok(Response));
            }
            catch (Exception)
            {
                var Response = new ResponseViewModel(false, HttpStatusCode.NoContent, "failed", null);
                return(Ok(Response));
            }
        }
Ejemplo n.º 16
0
        public async Task <int> AddActualIntencive(ActualIntencive actual)
        {
            if (_db != null)
            {
                await _db.ActualIntencive.AddAsync(actual);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 17
0
        public async Task <int> AddActualNeeds(ActualNeeds actual)
        {
            if (_db != null)
            {
                await _db.ActualNeeds.AddAsync(actual);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Ejemplo n.º 18
0
        //Adding new Task
        //each task has a typeID (1=visit, 2=alert, 3=requestInformation)
        //public async Task<int> AddTask(TaskTypeViewModel taskTypeViewModel, PhotoFileViewModel photoFileViewModel)
        public async Task <int> AddTask(TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                await _db.Task.AddAsync(taskTypeViewModel.task);

                //if the type is 1=visit so add visit
                if (taskTypeViewModel.task.TypeId == 1)
                {
                    await _db.Visit.AddAsync(taskTypeViewModel.visit);

                    await _db.SaveChangesAsync();

                    return(1);
                }
                //if the type is 2=alert so add alert
                else if (taskTypeViewModel.task.TypeId == 2)
                {
                    await _db.Alert.AddAsync(taskTypeViewModel.alert);

                    await _db.SaveChangesAsync();

                    return(1);
                }
                //if the type is 3=RequestInformation so add RequestInformation
                else if (taskTypeViewModel.task.TypeId == 3)
                {
                    await _db.RequestInformation.AddAsync(taskTypeViewModel.reqInfo);

                    await _db.SaveChangesAsync();

                    return(1);
                }
            }
            return(0);
        }