Exemplo n.º 1
0
        public Event Add(Event M)
        {
            cont.EventSet.Add(M);
            cont.SaveChanges();

            return(M);
        }
Exemplo n.º 2
0
        public Account Add(Account M)
        {
            cont.AccountSet.Add(M);
            cont.SaveChanges();

            return(M);
        }
Exemplo n.º 3
0
        public PaymentToPeers Add(PaymentToPeers M)
        {
            cont.PaymentToPeersSet.Add(M);
            cont.SaveChanges();

            return(M);
        }
        public Employee Add(Employee M)
        {
            cont.EmployeeSet.Add(M);
            cont.SaveChanges();

            return(M);
        }
Exemplo n.º 5
0
        public Client Add(Client M)
        {
            if (cont.ClientSet.Where(x => x.FIO == M.FIO).Count() == 0)
            {
                cont.ClientSet.Add(M);
            }

            cont.SaveChanges();

            return(M);
        }
        public IHttpActionResult PutOrder(int id, OrderViewModel order_view_model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order_view_model.Id)
            {
                return(BadRequest());
            }

            //把資料庫中的那筆資料讀出來
            var order = db.Orders.Find(order_view_model.Id);

            if (order == null)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!")));
            }
            else
            {
                try
                {
                    order.OrderDate   = order_view_model.OrderDate;
                    order.Customer_Id = order_view_model.Customer_Id;
                    order.OrderDetails.Clear();
                    Product product;
                    foreach (var detail in order_view_model.OrderDetails)
                    {
                        product = db.Products.Find(detail.Product_Id);
                        order.OrderDetails.Add(new OrderDetail {
                            Product = product, Quantity = detail.Quantity
                        });
                    }
                    db.Entry(order).OriginalValues["Timestamp"] = Convert.FromBase64String(order_view_model.TimestampString);
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(id))
                    {
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!"));
                    }
                    else
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, "這筆資料已被其他人修改!"));// ""
                    }
                }
            }

            return(Ok(toOrderViewModel(order)));
        }
        public IHttpActionResult PutProduct(int id, ProductViewModel product_view_model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product_view_model.Id)
            {
                return(BadRequest());
            }

            Category category = db.Categories.Find(product_view_model.Category_Id);

            if (category == null)
            {
                return(BadRequest("找不到對應的產品分類: " + product_view_model.Category_Id));
            }

            //把資料庫中的那筆資料讀出來
            Product product_db = db.Products.Find(id);

            if (product_db == null)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!")));
            }
            else
            {
                try
                {
                    product_db.Name     = product_view_model.Name;
                    product_db.Price    = product_view_model.Price;
                    product_db.Category = category;
                    db.Entry(product_db).OriginalValues["Timestamp"] = Convert.FromBase64String(product_view_model.TimestampString);
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(id))
                    {
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!"));
                    }
                    else
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, "這筆資料已被其他人修改!"));
                    }
                }
            }

            return(Ok(ToViewModel(product_db)));
        }
        public IEnumerable <Payments> GetCollection(bool flagofstatus)
        {
            foreach (Payments pm in cont.PaymentsSet)
            {
                try
                {
                    pm.StatusForSalary = cont.Pay_minSet.Where(x => x.Date == pm.Date && pm.Account.Id == x.Account.Id).Select(y => y.Finished).FirstOrDefault();
                }
                catch { pm.StatusForSalary = false; }
            }
            cont.SaveChanges();

            return(cont.PaymentsSet.OrderBy(cw => cw.Id));
        }
Exemplo n.º 9
0
        public IEnumerable <Pay_min> GetEmplPays(int id)
        {
            foreach (Pay_min pm in cont.Pay_minSet)
            {
                try
                {
                    var a = cont.Pay_minSet.Where(
                        x => x.Account.Id == pm.Account.Id && x.Date == pm.Date && x.Employee.Id == pm.Employee.Id).Select(y => y.Sum).Sum();
                    var b = cont.PaymentsSet.Where(x => x.Account.Id == pm.Account.Id && x.Date == pm.Date && x.Employee.Id == pm.Employee.Id).Select(y => y.Receipt).Sum();

                    pm.Finished = a ==
                                  b;
                }
                catch { pm.Finished = false; }
            }
            cont.SaveChanges();
            return(cont.Pay_minSet.Where(x => x.Employee.Id == id).OrderBy(cw => cw.Id));
        }
Exemplo n.º 10
0
        public IHttpActionResult PutcatCustomer(int id, CatCustomerViewModel Cat_CustomerView_Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != Cat_CustomerView_Model.Id)
            {
                return(BadRequest());
            }

            //把資料庫中的那筆資料讀出來
            var catCustomer_db = db.catCustomers.Find(id);

            if (catCustomer_db == null)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!")));
            }
            else
            {
                try
                {
                    catCustomer_db.Id   = Cat_CustomerView_Model.Id;
                    catCustomer_db.No   = Cat_CustomerView_Model.No;
                    catCustomer_db.Name = Cat_CustomerView_Model.Name;
                    db.Entry(catCustomer_db).OriginalValues["Timestamp"] = Convert.FromBase64String(Cat_CustomerView_Model.TimestampString);
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!catCustomerExists(id))
                    {
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!"));
                    }
                    else
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, "這筆資料已被其他人修改!"));// ""
                    }
                }
            }

            return(Ok(ToViewModel(catCustomer_db)));
        }
Exemplo n.º 11
0
        public IHttpActionResult PuttypeFactory(int id, TypeFactoryViewModel Type_FactoryView_Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != Type_FactoryView_Model.Id)
            {
                return(BadRequest());
            }

            //把資料庫中的那筆資料讀出來
            var typeFactory_db = db.typeFactories.Find(id);

            if (typeFactory_db == null)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!")));
            }
            else
            {
                try
                {
                    typeFactory_db.Id   = Type_FactoryView_Model.Id;
                    typeFactory_db.No   = Type_FactoryView_Model.No;
                    typeFactory_db.Name = Type_FactoryView_Model.Name;
                    db.Entry(typeFactory_db).OriginalValues["Timestamp"] = Convert.FromBase64String(Type_FactoryView_Model.TimestampString);
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!typeFactoryExists(id))
                    {
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!"));
                    }
                    else
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, "這筆資料已被其他人修改!"));// ""
                    }
                }
            }

            return(Ok(ToViewModel(typeFactory_db)));
        }
Exemplo n.º 12
0
        public Contract Add(int sumonly, int eventid, string client, DateTime sign, DateTime _event, DateTime pay1, DateTime pay2, DateTime pay3, int paysum1, int paysum2, int paysum3, string comment, int emplid)
        {
            Contract add = new Contract();

            add.Sum_only_contract = sumonly;
            add.EventSet          = cont.EventSet.Find(eventid);
            Client cladd = new Client();

            cladd.FIO = client;
            if (cont.ClientSet.Where(x => x.FIO == cladd.FIO).Count() == 0)
            {
                cont.ClientSet.Add(cladd);  cont.SaveChanges();
            }
            add.ClientSet     = cont.ClientSet.Where(x => x.FIO == cladd.FIO).FirstOrDefault();
            add.Date_of_sign  = sign;
            add.Date_of_event = _event;
            if (pay1 != default(DateTime))
            {
                add.Payment1Date = pay1;
            }
            if (pay2 != default(DateTime))
            {
                add.Payment2Date = pay2;
            }
            if (pay3 != default(DateTime))
            {
                add.Payment3Date = pay3;
            }
            if (paysum1 != 0)
            {
                add.Payment1Sum = paysum1;
            }
            if (paysum2 != 0)
            {
                add.Payment2Sum = paysum2;
            }

            if (paysum3 != 0)
            {
                add.Payment3Sum = paysum3;
            }


            add.Comment     = comment;
            add.Received    = 0;
            add.Sum_plus    = 0;
            add.Status      = Status.Активный.ToString();
            add.EmployeeSet = cont.EmployeeSet.Find(emplid); // Убрать потом при регистрации!!!!!!!
            add.Name        = add.Date_of_event.ToString().Split(' ')[0] + " — " + " (" + add.EmployeeSet.Name.First() + add.EmployeeSet.Surname.First() + ") " + add.ClientSet.FIO;
            cont.ContractSet.Add(add);
            cont.SaveChanges();
            return(add);
        }
        public IHttpActionResult PutCustomer(int id, CustomerViewModel customer_View_Model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != customer_View_Model.Id)
            {
                return(BadRequest());
            }

            //把資料庫中的那筆資料讀出來
            var customer_db = db.Customers.Find(id);

            if (customer_db == null)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!")));
            }
            else
            {
                try
                {
                    //customer_db.catCustomer.Name = customer_View_Model.CatName;
                    customer_db.Cat         = customer_View_Model.Cat;
                    customer_db.NO          = customer_View_Model.NO;
                    customer_db.Name        = customer_View_Model.Name;
                    customer_db.Sname       = customer_View_Model.Sname;
                    customer_db.Unid        = customer_View_Model.Unid;
                    customer_db.Contact1    = customer_View_Model.Contact1;
                    customer_db.Contact2    = customer_View_Model.Contact2;
                    customer_db.Email1      = customer_View_Model.Email1;
                    customer_db.Email2      = customer_View_Model.Email2;
                    customer_db.Email3      = customer_View_Model.Email3;
                    customer_db.Telephone1  = customer_View_Model.Telephone1;
                    customer_db.Telephone2  = customer_View_Model.Telephone2;
                    customer_db.Telephone3  = customer_View_Model.Telephone3;
                    customer_db.Website     = customer_View_Model.Website;
                    customer_db.Fax         = customer_View_Model.Fax;
                    customer_db.Address     = customer_View_Model.Address;
                    customer_db.Shipaddr    = customer_View_Model.Shipaddr;
                    customer_db.Invoiceaddr = customer_View_Model.Invoiceaddr;
                    customer_db.Pay         = customer_View_Model.Pay;
                    //customer_db.catPay.Name = customer_View_Model.PayName;
                    customer_db.Currency = customer_View_Model.Currency;
                    //customer_db.catCurrency.Name = customer_View_Model.CurrencyName;
                    customer_db.Lasttrade = customer_View_Model.Lasttrade;
                    customer_db.Note      = customer_View_Model.Note;
                    db.Entry(customer_db).OriginalValues["Timestamp"] = Convert.FromBase64String(customer_View_Model.TimestampString);
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerExists(id))
                    {
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!"));
                    }
                    else
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, "這筆資料已被其他人修改!"));// ""
                    }
                }
            }

            return(Ok(ToViewModel(customer_db)));
        }
Exemplo n.º 14
0
 public void Add(Salary s)
 {
     cont.SalarySet.Add(s);
     cont.SaveChanges();
 }
        public IHttpActionResult PutFactory(int id, FactoryViewModel factory_view_model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != factory_view_model.Id)
            {
                return(BadRequest());
            }

            //把資料庫中的那筆資料讀出來
            var factory_db = db.Factories.Find(id);

            if (factory_db == null)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!")));
            }
            else
            {
                try
                {
                    //factory_db.catFactory.Name = factory_view_model.CatName;
                    factory_db.Cat = factory_view_model.Cat;
                    //factory_db.typeFactory.Name = factory_view_model.TypeName;
                    factory_db.Type        = factory_view_model.Type;
                    factory_db.NO          = factory_view_model.NO;
                    factory_db.Name        = factory_view_model.Name;
                    factory_db.Sname       = factory_view_model.Sname;
                    factory_db.Unid        = factory_view_model.Unid;
                    factory_db.Contact1    = factory_view_model.Contact1;
                    factory_db.Contact2    = factory_view_model.Contact2;
                    factory_db.Email1      = factory_view_model.Email1;
                    factory_db.Email2      = factory_view_model.Email2;
                    factory_db.Email3      = factory_view_model.Email3;
                    factory_db.Telephone1  = factory_view_model.Telephone1;
                    factory_db.Telephone2  = factory_view_model.Telephone2;
                    factory_db.Telephone3  = factory_view_model.Telephone3;
                    factory_db.Website     = factory_view_model.Website;
                    factory_db.Fax         = factory_view_model.Fax;
                    factory_db.Address     = factory_view_model.Address;
                    factory_db.Shipaddr    = factory_view_model.Shipaddr;
                    factory_db.Invoiceaddr = factory_view_model.Invoiceaddr;
                    factory_db.Pay         = factory_view_model.Pay;
                    //factory_db.catPay.Name = factory_view_model.PayName;
                    factory_db.Currency = factory_view_model.Currency;
                    //factory_db.catCurrency.Name = factory_view_model.CurrencyName;
                    factory_db.Lasttrade = factory_view_model.Lasttrade;
                    factory_db.Note      = factory_view_model.Note;
                    db.Entry(factory_db).OriginalValues["Timestamp"] = Convert.FromBase64String(factory_view_model.TimestampString);
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FactoryExists(id))
                    {
                        throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound, "這筆資料已被刪除!"));
                    }
                    else
                    {
                        throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Conflict, "這筆資料已被其他人修改!"));// ""
                    }
                }
            }

            return(Ok(ToViewModel(factory_db)));
        }