public HttpResponseMessage GetCustomer(String CustomerNumber) { Log.Info(String.Format("Request received from:{0}/{1}", HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.UserHostName)); HttpResponseMessage resp; try { ARCOeCardEntities arcodb = new eCard.ARCOeCardEntities(); var customerlist = (from cus in arcodb.Customers where cus.CustomerNumber.Trim() == CustomerNumber.Trim() select cus).FirstOrDefault(); String _JSONCustomerList = JsonConvert.SerializeObject(customerlist); resp = new HttpResponseMessage(HttpStatusCode.OK); resp.Content = new StringContent(_JSONCustomerList, System.Text.Encoding.UTF8, "text/plain"); return(resp); } catch (Exception ex) { Log.Error(String.Format("Request received from:{0}/{1}", HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.UserHostName), ex); resp = new HttpResponseMessage(HttpStatusCode.InternalServerError); resp.Content = new StringContent(ex.Message, System.Text.Encoding.UTF8, "text/plain"); return(resp); } }
public HttpResponseMessage GetCustomerList() { Log.Info(String.Format("Request received from:{0}/{1}", HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.UserHostName)); HttpResponseMessage resp; try { ARCOeCardEntities arcodb = new eCard.ARCOeCardEntities(); var customerlist = (from cus in arcodb.Customers select new { Id = cus.ID, CompanyName = cus.CompanyName, CustomerNumber = cus.CustomerNumber.Trim(), CompanyNameAndNumber = cus.CustomerNumber.Trim() + "-" + cus.CompanyName }).OrderBy(Cus => Cus.Id).ToList(); String _JSONCustomerList = JsonConvert.SerializeObject(customerlist); resp = new HttpResponseMessage(HttpStatusCode.OK); resp.Content = new StringContent(_JSONCustomerList, System.Text.Encoding.UTF8, "text/plain"); return(resp); } catch (Exception ex) { Log.Error(String.Format("Request received from:{0}/{1}", HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.UserHostName), ex); resp = new HttpResponseMessage(HttpStatusCode.InternalServerError); resp.Content = new StringContent(ex.Message, System.Text.Encoding.UTF8, "text/plain"); return(resp); } }
public IHttpActionResult UpdateOrder([FromBody] SalesOrder Order) { ARCOeCardEntities arcodb = new eCard.ARCOeCardEntities(); var OrdertoUpdate = arcodb.SalesOrders.Where(a => a.ID == Order.ID).FirstOrDefault(); try { OrdertoUpdate.Status = Convert.ToInt32(Order.Status); OrdertoUpdate.AssignedTO = Order.AssignedTO; arcodb.SaveChanges(); return(Content(HttpStatusCode.OK, Order)); } catch (Exception ex) { Log.Error("There was an error while updating an order", ex); return(Content(HttpStatusCode.InternalServerError, "There was an error while updating an order")); } }
public IHttpActionResult GetStatusList() { ARCOeCardEntities arcodb = new eCard.ARCOeCardEntities(); try { var StatusList = (from status in arcodb.OrderStatus select new { StatusId = status.Id, Status = status.Status }).OrderBy(a => a.StatusId).ToList(); return(Content(HttpStatusCode.OK, StatusList)); } catch (Exception ex) { Log.Error("There was an error while loading a order", ex); return(Content(HttpStatusCode.InternalServerError, "There was an error while loading a order")); } }
public IHttpActionResult SetUserClaimed(int UserId, int orderitemid) { ARCOeCardEntities arcodb = new eCard.ARCOeCardEntities(); try { SalesOrder So = arcodb.SalesOrders.Where(a => a.ID == orderitemid).FirstOrDefault(); PrenotesUser User = arcodb.PrenotesUsers.Where(a => a.Id == UserId).FirstOrDefault(); So.ModifiedDate = DateTime.Now; So.Status = 4; So.ModifiedBy = UserId; So.AssignedTO = User.Id; arcodb.SaveChanges(); return(Content(HttpStatusCode.OK, "SUCCESS")); } catch (Exception ex) { Log.Error("There was an error while assigning the user.", ex); return(Content(HttpStatusCode.InternalServerError, "There was an error while assigning the user.")); } }
public IHttpActionResult LoadFilteredOrderList([FromBody] FilteredOrderListVM filter) { if (filter == null || !ModelState.IsValid) { return(Content(HttpStatusCode.BadRequest, "Request body not valid")); } ARCOeCardEntities arcodb = new eCard.ARCOeCardEntities(); PrenotesUser user1 = arcodb.PrenotesUsers.Where(a => a.Username == User.Identity.Name).FirstOrDefault(); //filter.Site = null; int siteid = Convert.ToInt32(filter.Site); //SiteLocation sitelocation = arcodb.SiteLocations.Where(s => s.ID == siteid).FirstOrDefault(); List <FilteredOrderListVM> Orders = new List <FilteredOrderListVM>(); if (user1.Admin == true || user1.Manager == true) { Orders = (from orders in arcodb.SalesOrders join cus in arcodb.Customers on orders.CustomerNumber equals cus.CustomerNumber join site in arcodb.SiteLocations on orders.SiteLocationId equals site.ID join status in arcodb.OrderStatus on orders.Status equals status.Id join user in arcodb.PrenotesUsers on orders.AssignedTO equals user.Id into userlist from PrenotesUser in userlist.DefaultIfEmpty() where (filter.StatusForProgress != 0 ? orders.Status == filter.StatusForProgress : orders.Status != 3) && (String.IsNullOrEmpty(filter.CustomerName) || (cus.CompanyName.Contains(filter.CustomerName) || cus.CustomerNumber.Contains(filter.CustomerName))) && (filter.Site == null || orders.SiteLocationId == siteid) && (filter.SalesOrderNumber == null || orders.SalesOrderNumber.Contains(filter.SalesOrderNumber)) && (site.Status != false) && (String.IsNullOrEmpty(filter.Assignusername) || (PrenotesUser.Username.Contains(filter.Assignusername))) // (filter.CreatedDate == null || orders.CreatedDate >= filter.CreatedDate) && //(filter.EndDate == null || note.CreatedDate.Date <= filter.EndDate.Value.Date) select new FilteredOrderListVM { OrderId = orders.ID, Customer = orders.CustomerNumber + "-" + cus.CompanyName, SalesOrderNumber = orders.SalesOrderNumber, Site = orders.SiteLocation.SiteLocation1, StartDate = orders.CreatedDate, LastUpdatedDate = orders.CreatedDate, LastStartDate = orders.ModifiedDate, LastEndUpdate = orders.ModifiedDate, Status = status.Status, CityNState = cus.City + "," + cus.State, UserName = PrenotesUser.Username != null ? PrenotesUser.Username : "******" }) .ToList() .Where(a => filter.StatusForDate == false ? (filter.StartDate == null || a.StartDate.Value.Date >= filter.StartDate.Value.Date) : filter.StartDate == null || a.LastStartDate.Value.Date >= filter.StartDate.Value.Date).DefaultIfEmpty() .Where(a => filter.StatusForDate == false ? (filter.LastUpdatedDate == null || a.LastUpdatedDate.Value.Date <= filter.LastUpdatedDate.Value.Date) : filter.LastUpdatedDate == null || a.LastEndUpdate.Value.Date <= filter.LastUpdatedDate.Value.Date).DefaultIfEmpty() .ToList(); } else { Orders = (from orders in arcodb.SalesOrders join cus in arcodb.Customers on orders.CustomerNumber equals cus.CustomerNumber join site in arcodb.SiteLocations on orders.SiteLocationId equals site.ID join status in arcodb.OrderStatus on orders.Status equals status.Id join user in arcodb.PrenotesUsers on orders.AssignedTO equals(int?) user.Id into userlist from PrenotesUser in userlist.DefaultIfEmpty() where //(filter.StatusForProgress != 0 ? (orders.Status == filter.StatusForProgress || orders.AssignedTO == (int?)null || PrenotesUser.Id.Equals(user1.Id) ): (orders.AssignedTO == (int?)null || PrenotesUser.Id.Equals(user1.Id) && orders.Status != 3)) (filter.StatusForProgress == 0 ? (orders.AssignedTO == (int?)null && orders.Status != 3 || PrenotesUser.Id.Equals(user1.Id) && orders.Status != 3) : filter.StatusForProgress == 1 ? (orders.Status == filter.StatusForProgress && PrenotesUser.Id.Equals(user1.Id)) : filter.StatusForProgress == 2 ? (orders.Status == filter.StatusForProgress || orders.AssignedTO == (int?)null) : filter.StatusForProgress == 3 ? (orders.Status == filter.StatusForProgress && PrenotesUser.Id.Equals(user1.Id)) : (orders.Status == filter.StatusForProgress && PrenotesUser.Id.Equals(user1.Id))) && (String.IsNullOrEmpty(filter.CustomerName) || (cus.CompanyName.Contains(filter.CustomerName) || cus.CustomerNumber.Contains(filter.CustomerName))) && (filter.Site == null || orders.SiteLocationId == siteid) && (filter.SalesOrderNumber == null || orders.SalesOrderNumber.Contains(filter.SalesOrderNumber)) && (site.Status != false) && (String.IsNullOrEmpty(filter.Assignusername) || (PrenotesUser.Username.Contains(filter.Assignusername))) // (filter.CreatedDate == null || orders.CreatedDate >= filter.CreatedDate) && //(filter.EndDate == null || note.CreatedDate.Date <= filter.EndDate.Value.Date) select new FilteredOrderListVM { OrderId = orders.ID, Customer = orders.CustomerNumber + "-" + cus.CompanyName, SalesOrderNumber = orders.SalesOrderNumber, Site = orders.SiteLocation.SiteLocation1, StartDate = orders.CreatedDate, LastUpdatedDate = orders.CreatedDate, LastStartDate = orders.ModifiedDate, LastEndUpdate = orders.ModifiedDate, Status = status.Status, CityNState = cus.City + "," + cus.State, UserName = PrenotesUser.Username != null ? PrenotesUser.Username : "******" }) .ToList() .Where(a => filter.StatusForDate == false ? (filter.StartDate == null || a.StartDate.Value.Date >= filter.StartDate.Value.Date) : filter.StartDate == null || a.LastStartDate.Value.Date >= filter.StartDate.Value.Date).DefaultIfEmpty() .Where(a => filter.StatusForDate == false ? (filter.LastUpdatedDate == null || a.LastUpdatedDate.Value.Date <= filter.LastUpdatedDate.Value.Date) : filter.LastUpdatedDate == null || a.LastEndUpdate.Value.Date <= filter.LastUpdatedDate.Value.Date).DefaultIfEmpty() .ToList(); } if (filter.DateForSearch != 0) { filter.Sorting = "datecreated"; } if (Orders.Count == 1 && Orders[0] == null) { return(Content(HttpStatusCode.OK, Orders)); } // Filter the list according to the input filter try { #region Orders Sorting if (String.IsNullOrWhiteSpace(filter.Sorting)) { Orders = Orders.OrderByDescending(i => i.LastEndUpdate).ToList(); } else if (filter.Direction == "desc") { switch (filter.Sorting) { case "customerNumber": Orders = Orders.OrderByDescending(i => i.Customer).ToList(); break; case "site": Orders = Orders.OrderByDescending(i => i.Site).ToList(); break; case "salesordernumber": Orders = Orders.OrderByDescending(i => i.SalesOrderNumber).ToList(); break; case "datecreated": Orders = Orders.OrderByDescending(i => i.LastUpdatedDate).ToList(); break; case "lastupdated": Orders = Orders.OrderByDescending(i => i.LastEndUpdate).ToList(); break; case "citynstate": Orders = Orders.OrderByDescending(i => i.CityNState).ToList(); break; case "username": Orders = Orders.OrderByDescending(i => i.UserName).ToList(); break; default: Orders = Orders.OrderByDescending(i => i.OrderId).ToList(); break; } } else { switch (filter.Sorting) { case "customerNumber": Orders = Orders.OrderBy(i => i.Customer).ToList(); break; case "site": Orders = Orders.OrderBy(i => i.Site).ToList(); break; case "salesordernumber": Orders = Orders.OrderBy(i => i.SalesOrderNumber).ToList(); break; case "datecreated": Orders = Orders.OrderBy(i => i.LastUpdatedDate).ToList(); break; case "lastupdated": Orders = Orders.OrderBy(i => i.LastEndUpdate).ToList(); break; case "citynstate": Orders = Orders.OrderByDescending(i => i.CityNState).ToList(); break; case "username": Orders = Orders.OrderByDescending(i => i.UserName).ToList(); break; default: Orders = Orders.OrderBy(i => i.OrderId).ToList(); break; } } #endregion int OrdersCount = Orders.Count(); int pages = OrdersCount / filter.PageSize + ((OrdersCount % filter.PageSize > 0) ? 1 : 0); FilteredOrdersListReturnVM result = new FilteredOrdersListReturnVM(); result.Pages = pages; result.Orders = Orders.Skip((filter.Page - 1) * filter.PageSize).Take(filter.PageSize).ToList(); return(Content(HttpStatusCode.OK, result)); } catch (Exception ex) { Log.Error("There was an unexpected error while filtering a list of Orders.", ex); return(Content(HttpStatusCode.InternalServerError, "There was an unexpected error while filtering a list of Orders.")); } }
public IHttpActionResult LoadOrder(int OrderId) { ARCOeCardEntities arcodb = new eCard.ARCOeCardEntities(); try { String _ServerFolder = String.Format(@"{0}\", ConfigurationManager.AppSettings["FileServerPath"].ToString()); var Order = (from order in arcodb.SalesOrders join Cus in arcodb.Customers on order.CustomerNumber equals Cus.CustomerNumber join site in arcodb.SiteLocations on order.SiteLocationId equals site.ID join status in arcodb.OrderStatus on order.Status equals status.Id join user in arcodb.PrenotesUsers on order.AssignedTO equals user.Id into userlist from PrenotesUser in userlist.DefaultIfEmpty() where order.ID == OrderId && site.Status != false select new { OrderId = order.ID, CustomerNumber = order.CustomerNumber + "-" + Cus.CompanyName, Site = site.SiteLocation1, SaleOrderNumber = order.SalesOrderNumber, Status = order.Status, FilePath = _ServerFolder + order.FolderPath, User = order.AssignedTO, ModifiedId = order.ModifiedBy, AssignedUser = userlist.Where(a => a.Id == order.ModifiedBy).Select(a => a.DisplayName).FirstOrDefault() }).FirstOrDefault(); if (Order.ModifiedId != null) { Order = (from order in arcodb.SalesOrders join Cus in arcodb.Customers on order.CustomerNumber equals Cus.CustomerNumber join site in arcodb.SiteLocations on order.SiteLocationId equals site.ID join status in arcodb.OrderStatus on order.Status equals status.Id join username in arcodb.PrenotesUsers on order.ModifiedBy equals username.Id join user in arcodb.PrenotesUsers on order.AssignedTO equals user.Id into userlist from PrenotesUser in userlist.DefaultIfEmpty() where order.ID == OrderId && site.Status != false select new { OrderId = order.ID, CustomerNumber = order.CustomerNumber + "-" + Cus.CompanyName, Site = site.SiteLocation1, SaleOrderNumber = order.SalesOrderNumber, Status = order.Status, FilePath = _ServerFolder + order.FolderPath, User = order.AssignedTO, ModifiedId = order.ModifiedBy, AssignedUser = username.DisplayName }).FirstOrDefault(); } return(Content(HttpStatusCode.OK, Order)); } catch (Exception ex) { Log.Error("There was an error while loading a order", ex); return(Content(HttpStatusCode.InternalServerError, "There was an error while loading a order")); } }
public IHttpActionResult LoadUserList([FromBody] UserListVM filter) { if (filter == null || !ModelState.IsValid) { return(Content(HttpStatusCode.BadRequest, "Request body not valid")); } ARCOeCardEntities arcodb = new eCard.ARCOeCardEntities(); int siteid = Convert.ToInt32(filter.SiteId); //SiteLocation sitelocation = arcodb.SiteLocations.Where(s => s.ID == siteid).FirstOrDefault(); List <UserListVM> UserList = (from User in arcodb.PrenotesUsers join sitename in arcodb.SiteLocations on User.DefaultSite equals sitename.ID where (String.IsNullOrEmpty(filter.UserName) || (User.Username.Contains(filter.UserName))) && (filter.SiteId == 0 || User.DefaultSite == siteid) && User.Deleted == false && sitename.Status != false // (filter.CreatedDate == null || orders.CreatedDate >= filter.CreatedDate) && //(filter.EndDate == null || note.CreatedDate.Date <= filter.EndDate.Value.Date) select new UserListVM { UserName = User.Username, Id = User.Id, Email = User.Email, SiteName = sitename.SiteLocation1, CreatedDate = User.CreatedDate, LastUpdatedDate = User.ModifiedDate, }) .ToList() //.Where(a => filter.StatusForDate == false ? (filter.StartDate == null || a.StartDate.Value.Date >= filter.StartDate.Value.Date) : filter.StartDate == null || a.LastStartDate.Value.Date >= filter.StartDate.Value.Date).DefaultIfEmpty() //.Where(a => filter.StatusForDate == false ? (filter.LastUpdatedDate == null || a.LastUpdatedDate.Value.Date <= filter.LastUpdatedDate.Value.Date) : filter.LastUpdatedDate == null || a.LastEndUpdate.Value.Date <= filter.LastUpdatedDate.Value.Date).DefaultIfEmpty() .ToList(); // Filter the list according to the input filter try { #region Orders Sorting if (String.IsNullOrWhiteSpace(filter.Sorting)) { UserList = UserList.OrderByDescending(i => i.LastUpdatedDate).ToList(); } else if (filter.Direction == "desc") { switch (filter.Sorting) { case "UserName": UserList = UserList.OrderByDescending(i => i.UserName).ToList(); break; case "SiteName": UserList = UserList.OrderByDescending(i => i.SiteName).ToList(); break; case "lastupdated": UserList = UserList.OrderByDescending(i => i.LastUpdatedDate).ToList(); break; default: UserList = UserList.OrderByDescending(i => i.LastUpdatedDate).ToList(); break; } } else { switch (filter.Sorting) { case "UserName": UserList = UserList.OrderByDescending(i => i.UserName).ToList(); break; case "SiteName": UserList = UserList.OrderByDescending(i => i.SiteName).ToList(); break; case "lastupdated": UserList = UserList.OrderByDescending(i => i.LastUpdatedDate).ToList(); break; default: UserList = UserList.OrderByDescending(i => i.LastUpdatedDate).ToList(); break; } } #endregion int UserListCount = UserList.Count(); int pages = UserListCount / filter.PageSize + ((UserListCount % filter.PageSize > 0) ? 1 : 0); UserListReturnVM result = new UserListReturnVM(); result.Pages = pages; result.Users = UserList.Skip((filter.Page - 1) * filter.PageSize).Take(filter.PageSize).ToList(); return(Content(HttpStatusCode.OK, result)); } catch (Exception ex) { Log.Error("There was an unexpected error while filtering a list of Orders.", ex); return(Content(HttpStatusCode.InternalServerError, "There was an unexpected error while filtering a list of Orders.")); } }