public IHttpActionResult PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order.OrderId)
            {
                return(BadRequest());
            }

            db.Entry(order).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public IHttpActionResult PutRestaurant(int id, Restaurant restaurant)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != restaurant.ResId)
            {
                return(BadRequest());
            }

            db.Entry(restaurant).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RestaurantExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutAdmin_Table(int id, Admin_Table admin_Table)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != admin_Table.AminId)
            {
                return(BadRequest());
            }

            db.Entry(admin_Table).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Admin_TableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 4
0
 //insert customer
 public HttpResponseMessage Post(Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Customers.Add(customer);
         db.SaveChanges();
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, customer);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = customer.CustomerID }));
         return(response);
     }
     else
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
 }
Esempio n. 5
0
        public JsonResult SaveSale(int Id, int ProductId, int CustomerId, int StoreId, DateTime SaleDate)
        {
            //This method is used to save the edited information about the Customer  and to create a new
            //method
            var result = false;

            if (Id > 0)
            {
                try

                {
                    ProductSold SaleToBeUpdated = db.ProductSolds.SingleOrDefault(x => x.Id == Id);
                    SaleToBeUpdated.ProductId  = ProductId;
                    SaleToBeUpdated.CustomerId = CustomerId;
                    SaleToBeUpdated.StoreId    = StoreId;
                    SaleToBeUpdated.Date       = SaleDate;

                    db.SaveChanges();
                    result = true;
                }
                catch (Exception exp)
                {
                }
            }

            else
            {
                //The following code insersts new record
                try
                {
                    CustomerDbEntities db   = new CustomerDbEntities();
                    ProductSold        Sale = new ProductSold();
                    Sale.ProductId  = ProductId;
                    Sale.CustomerId = CustomerId;
                    Sale.StoreId    = StoreId;
                    Sale.Date       = SaleDate;
                    db.ProductSolds.Add(Sale);
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveProduct(int Id, string Name, Decimal Price)
        {
            var result = false;

            if (Id > 0)
            {
                try

                {
                    Product ProducttoBeUpdated = db.Products.SingleOrDefault(x => x.Id == Id);
                    ProducttoBeUpdated.Name  = Name;
                    ProducttoBeUpdated.Price = Price;
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception exp)
                {
                }
            }

            else
            {
                //The following code insersts new record
                try
                {
                    CustomerDbEntities db = new CustomerDbEntities();

                    // List<Product> list = db.Products.ToList();
                    //ViewBag.DepartmentList = new SelectList(list, "DepartmentId", "DepartmentName");

                    Product P1 = new Product();

                    P1.Name  = Name;
                    P1.Price = Price;
                    db.Products.Add(P1);
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveCustomer(int Id, string Name, string Address)
        {
            //This method is used to save the edited information about the Customer  and to create a new
            //method
            var result = false;

            if (Id > 0)
            {
                try

                {
                    Customer CustomertoBeUpdated = db.Customers.SingleOrDefault(x => x.Id == Id);
                    CustomertoBeUpdated.Name    = Name;
                    CustomertoBeUpdated.Address = Address;
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception exp)
                {
                }
            }

            else
            {
                //The following code insersts new record
                try
                {
                    CustomerDbEntities db          = new CustomerDbEntities();
                    Customer           newCustomer = new Customer();
                    newCustomer.Name    = Name;
                    newCustomer.Address = Address;
                    db.Customers.Add(newCustomer);
                    db.SaveChanges();
                    result = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
        public void InsertNewContact(int customerID)
        {
            var cc = new CUSTOMER_CONTACT
            {
                CUSTOMER_ROWID   = customerID,
                CONTACT_ACTIVE   = true,
                isAccountPayable = false,
                isProjectManager = false,
                isSiteContact    = false,
            };

            _db.CUSTOMER_CONTACT.Add(cc);
            _db.SaveChanges();
        }
Esempio n. 9
0
        public void GetAllAccounts(string sfProjectID, int misJobID, int employeeNumber, enterprise.QueryResult result)
        {
            try
            {
                //create service client to call API endpoint
                using (enterprise.SoapClient queryClient = new enterprise.SoapClient("Soap", apiAddr))
                {
                    if (result == null || (result != null && result.size == 0))
                    {
                        return;
                    }

                    //cast query results
                    IEnumerable <enterprise.Bill_Quote_Install__c> billQuoteShipList = result.records.Cast <enterprise.Bill_Quote_Install__c>();

                    //show results
                    foreach (var bqs in billQuoteShipList)
                    {
                        bool hasOne = false;
                        if (bqs.Billing_Company_Name__r != null && bqs.Billing_Contact_Name__r != null)
                        {
                            HandleAccount(bqs.Billing_Company_Name__r.Name, bqs.Billing_Company_Street__c, bqs.Billing_Company_Province__c, bqs.Billing_Company_Postal_Code__c,
                                          bqs.Billing_Company_City__c, bqs.Billing_Company_Country__c, bqs.Billing_Contact_Name__r.FirstName,
                                          bqs.Billing_Contact_Name__r.LastName, bqs.Billing_Contact_Phone__c, bqs.Billing_Contact_Name__r.Id, bqs.Billing_Account_Intersection__c, bqs.Billing_Account_Corner__c, misJobID, employeeNumber, bqs.Billing_Company_Name__r.Id, 1, bqs.Billing_Company_Name__r.Legal_Name__c);
                            hasOne = true;
                        }

                        if (bqs.Quoting_Company_Name__r != null && bqs.Quoting_Contact_Name__r != null)
                        {
                            HandleAccount(bqs.Quoting_Company_Name__r.Name, bqs.Quoting_Company_Street__c, bqs.Quoting_Company_Province__c, bqs.Quoting_Company_Postal_Code__c,
                                          bqs.Quoting_Company_City__c, bqs.Quoting_Company_Country__c, bqs.Quoting_Contact_Name__r.FirstName,
                                          bqs.Quoting_Contact_Name__r.LastName, bqs.Quoting_Contact_Phone__c, bqs.Quoting_Contact_Name__r.Id, bqs.Quoting_Account_Intersection__c, bqs.Quoting_Account_Corner__c, misJobID, employeeNumber, bqs.Quoting_Company_Name__r.Id, 2, bqs.Billing_Company_Name__r.Legal_Name__c);
                            hasOne = true;
                        }

                        if (bqs.Installing_Company_Name__r != null && bqs.Installing_Contact_Name__r != null)
                        {
                            HandleAccount(bqs.Installing_Company_Name__r.Name, bqs.Installing_Company_Street__c, bqs.Installing_Company_Province__c, bqs.Installing_Company_Postal_Code__c,
                                          bqs.Installing_Company_City__c, bqs.Installing_Company_Country__c, bqs.Installing_Contact_Name__r.FirstName,
                                          bqs.Installing_Contact_Name__r.LastName, bqs.Installing_Contact_Phone__c, bqs.Installing_Contact_Name__r.Id, bqs.Installing_Account_Intersection__c, bqs.Installing_Account_Corner__c, misJobID, employeeNumber, bqs.Installing_Company_Name__r.Id, 3, bqs.Billing_Company_Name__r.Legal_Name__c);
                            hasOne = true;
                        }

                        /* delete default row if there exists at least one bill/quote/install */
                        if (hasOne)
                        {
                            var records = _db.Sales_JobMasterList_Customer.Where(x => x.jobID == misJobID && x.cID == 0 && x.contactName == 0 && x.isBillTo == false && x.isQuoteTo == false && x.isInstallOrShipTo == false).ToList();
                            if (records.Any())
                            {
                                foreach (var r in records)
                                {
                                    //delete it
                                    _db.Sales_JobMasterList_Customer.Remove(r);
                                }
                                _db.SaveChanges();
                            }
                        }
                    }
                    LogMethods.Log.Debug("GetAllAccounts:Debug:" + "Done");
                }
            }
            catch (Exception e)
            {
                LogMethods.Log.Error("GetAllAccounts:Error:" + e.Message);
            }
        }
Esempio n. 10
0
 public void Insert(CUSTOMER customer)
 {
     _db.CUSTOMERs.Add(customer);
     _db.SaveChanges();
     RowID = customer.ROWID;
 }
Esempio n. 11
0
 public int Complete()
 {
     return(_context.SaveChanges());
 }
Esempio n. 12
0
        /// <summary>
        /// Create a new Lead
        /// </summary>
        /// <param name="createViewModel"></param>
        /// <param name="username">user name, such as type whoami under command line \\F01\anh.tran</param>
        public void CreateLead(LeadModifyViewMode createViewModel, string username)
        {
            try
            {
                var lead = createViewModel.Lead;
                //Svae Address
                _db.CrmLeadAddresses.Add(createViewModel.Address);
                _db.SaveChanges();
                var addressID = createViewModel.Address.AddressID;

                //Save Lead
                lead.AddressID = addressID;
                var emp = new CrmEmployee(username);
                lead.CreatedBy     = emp.UserEmployeeID;
                lead.CreatedAt     = DateTime.Now;
                lead.LastUpdatedBy = emp.UserEmployeeID;
                lead.LastUpdatedAt = DateTime.Now;
                //status
                if (lead.AccountExcutive > 0)
                {
                    lead.AeAssignedAt = DateTime.Now;
                }
                else
                {
                    lead.AeAssignedAt = null;
                }
                _db.CrmLeads.Add(lead);
                _db.SaveChanges();
                LogMethods.Log.Debug("CreateLead:Debug:" + "Done");
            }
            catch (DbEntityValidationException dbEx)
            {
                LogMethods.Log.Error("CreateLead:Error:" + dbEx.Message);
            }
        }