// Delete Category public async Task <CosApiResponse> DeleteCatgory(RequestModelBase request) { var response = new CosApiResponse(); try { using (var _db = new CosContext()) { /* delete */ var cateDB = _db.Categories.Where(x => x.Id == request.ID && x.Status == (byte)Constants.EStatus.Actived).FirstOrDefault(); if (cateDB != null) { cateDB.Status = (byte)Constants.EStatus.Deleted; if (_db.SaveChanges() > 0) { response.Success = true; } else { response.Message = "Unable to delete category"; } } else { response.Message = " Unable to find category"; NSLog.Logger.Info("Response Delete Category", response); } } } catch (Exception ex) { NSLog.Logger.Error("Error Delete Category", null, response, ex); } finally { } return(response); }
// Delete Order public async Task <CosApiResponse> DeleteOrder(RequestModelBase request) { var response = new CosApiResponse(); try { using (var _db = new CosContext()) { /* delete */ var OrderDB = _db.Orders.Where(o => o.Id == request.ID && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault(); if (OrderDB != null) { OrderDB.Status = (byte)Constants.EStatus.Deleted; /* Save change data */ if (_db.SaveChanges() > 0) { response.Success = true; } else { response.Message = "Unable to delete Order"; } } else { response.Message = "Unable to find Order"; } NSLog.Logger.Info("Response Delete Order", response); } } catch (Exception ex) { NSLog.Logger.Error("Error Delete Order", null, response, ex); } finally { /*_db.Refresh();*/ } return(response); }
// Create Or Update Order public async Task <CosApiResponse> CreateUpdateOrder(OrderRequest request) { var response = new CosApiResponse(); try { using (var _db = new CosContext()) { var Order = request.Order; if (string.IsNullOrEmpty(Order.Id)) /* insert */ { Order.Id = Guid.NewGuid().ToString(); var orderDB = new Order() { Id = Order.Id, CustomerId = Order.CustomerId, ReceiptNo = Order.ReceiptNo, OrderNo = Order.OrderNo, TotalBill = Order.TotalBill, Discount = Order.Discount, }; _db.Orders.Add(orderDB); } else /* update */ { var orderDB = _db.Orders.Where(o => o.Id == Order.Id && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault(); orderDB.CustomerId = Order.CustomerId; orderDB.ReceiptNo = Order.ReceiptNo; orderDB.OrderNo = Order.OrderNo; orderDB.TotalBill = Order.TotalBill; orderDB.Discount = Order.Discount; } /* save data */ if (_db.SaveChanges() > 0) { response.Success = true; } else { response.Message = "Unable to add new or update Order"; } NSLog.Logger.Info("Response Create Update Order", response); } } catch (Exception ex) { NSLog.Logger.Error("Error Create Update Order", null, response, ex); } finally { /*_db.Refresh();*/ } return(response); }
// Create Update Product public async Task <CosApiResponse> CreateUpdateProduct(CreateUpdateProductRequest request) { var response = new CosApiResponse(); try { using (var _db = new CosContext()) { var pro = request.Pro; if (string.IsNullOrEmpty(pro.ID)) /* insert */ { pro.ID = Guid.NewGuid().ToString(); var proDB = new Product() { Id = pro.ID, Name = pro.Name, CategoryId = pro.CateID, Price = (decimal)pro.Price, Status = (byte)Constants.EStatus.Deleted, }; _db.Products.Add(proDB); } else /* update */ { var proDB = _db.Products.Where(o => o.Id == pro.ID && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault(); if (proDB != null) { proDB.Price = (decimal)pro.Price; proDB.Name = pro.Name; proDB.CategoryId = pro.CateID; } } /* save data */ if (_db.SaveChanges() > 0) { response.Success = true; } else { response.Message = "Unable to add new or update product."; } NSLog.Logger.Info("ResponseCreateUpdateProduct", response); } } catch (Exception ex) { NSLog.Logger.Error("ErrorCreateUpdateProduct", null, response, ex); } finally { /*_db.Refresh();*/ } return(response); }
// CreateUpdateCustomer public async Task <CosApiResponse> CreateUpdateCustomer(CustomerRequest request) { var response = new CosApiResponse(); try { using (var _db = new CosContext()) { var customer = request.Customer; if (string.IsNullOrEmpty(customer.Id)) /* insert */ { customer.Id = Guid.NewGuid().ToString(); var customerDB = new Customer() { Id = customer.Id, Name = customer.Name, Email = customer.Email, City = customer.City, }; _db.Customers.Add(customerDB); } else /* update */ { var customerDB = _db.Customers.Where(o => o.Id == customer.Id && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault(); customerDB.Name = customer.Name; customerDB.Email = customer.Email; customerDB.City = customer.City; } /* save data */ if (_db.SaveChanges() > 0) { response.Success = true; } else { response.Message = "Unable to add new or update customer"; } NSLog.Logger.Info("Response Create Update customer", response); } } catch (Exception ex) { NSLog.Logger.Error("Error Create Update customer", null, response, ex); } finally { /*_db.Refresh();*/ } return(response); }
// Create Or Update Category public async Task <CosApiResponse> CreateUpdateCategory(CategoryRequest requests) { var response = new CosApiResponse(); try { using (var _db = new CosContext()) { var Cate = requests.Category; if (string.IsNullOrEmpty(Cate.Id)) { Cate.Id = Guid.NewGuid().ToString(); var cateDB = new Category() { Id = Cate.Id, Name = Cate.Name, ParentId = Cate.ParentId, }; _db.Categories.Add(cateDB); } else { var cateDB = _db.Categories.Where(x => x.Id == Cate.Id && x.Status == (byte)Constants.EStatus.Actived).FirstOrDefault(); cateDB.Name = Cate.Name; cateDB.ParentId = Cate.ParentId; } if (_db.SaveChanges() > 0) { response.Success = true; } else { response.Message = "Unable to add new or update category"; NSLog.Logger.Info("Response Create or Update Category", response); } } } catch (Exception ex) { NSLog.Logger.Error("Error Create Or Update Category", null, response, ex); } finally { } return(response); }
// Create Or Update role public async Task <CosApiResponse> CreateUpdateRole(RoleRequest request) { var response = new CosApiResponse(); try { using (var _db = new CosContext()) { var role = request.Role; if (string.IsNullOrEmpty(role.Id)) /* insert */ { role.Id = Guid.NewGuid().ToString(); var roleDB = new Role() { Id = role.Id, Name = role.Name, RoleLevel = role.RoleLevel, }; _db.Roles.Add(roleDB); } else /* update */ { var roleDB = _db.Roles.Where(o => o.Id == role.Id && o.Status == (byte)Constants.EStatus.Actived).FirstOrDefault(); roleDB.Name = role.Name; } /* save data */ if (_db.SaveChanges() > 0) { response.Success = true; } else { response.Message = "Unable to add new or update role"; } NSLog.Logger.Info("Response Create Update role", response); } } catch (Exception ex) { NSLog.Logger.Error("Error Create Update role", null, response, ex); } finally { /*_db.Refresh();*/ } return(response); }