Exemplo n.º 1
0
 public IHttpActionResult DeleteUser(int UserId)
 {
     try
     {
         PrenotesUser User = arcodb.PrenotesUsers.Where(a => a.Id == UserId).FirstOrDefault();
         User.Deleted = true;
         arcodb.SaveChanges();
         return(Content(HttpStatusCode.OK, "Deleted"));
     }
     catch (Exception ex)
     {
         Log.Error("There was an unexpected error while filtering a list of users from AD.", ex);
         return(Content(HttpStatusCode.InternalServerError, "There was an unexpected error while filtering a list of users from AD."));
     }
 }
Exemplo n.º 2
0
        public IHttpActionResult UpdateUsertoDB([FromBody] UpdateUserVM filter)
        {
            if (filter == null)
            {
                return(Content(HttpStatusCode.BadRequest, "Request body not valid"));
            }

            try
            {
                PrenotesUser UpdateUser = arcodb.PrenotesUsers.Where(a => a.Username == filter.user && a.Deleted == false).FirstOrDefault();
                UpdateUser.Admin       = filter.admin;
                UpdateUser.Manager     = filter.manager;
                UpdateUser.DefaultSite = filter.defaultsite;
                List <UserSiteLocation> UserOldLocation = arcodb.UserSiteLocations.Where(a => a.UserId == UpdateUser.Id).ToList();
                arcodb.UserSiteLocations.RemoveRange(UserOldLocation);



                //arcodb.PrenotesUsers.Add(UpdateUser);
                arcodb.SaveChanges();

                UserSiteLocation bridge1 = new UserSiteLocation();
                bridge1.SiteLocationId = filter.defaultsite;
                bridge1.UserId         = UpdateUser.Id;
                arcodb.UserSiteLocations.Add(bridge1);
                foreach (var item in filter.othersites)
                {
                    if (item.selected == true)
                    {
                        UserSiteLocation bridge = new UserSiteLocation();
                        bridge.SiteLocationId = item.SiteID;
                        bridge.UserId         = UpdateUser.Id;
                        arcodb.UserSiteLocations.Add(bridge);
                    }
                }

                arcodb.SaveChanges();

                return(Content(HttpStatusCode.OK, "User added successfully"));
            }
            catch (Exception ex)
            {
                Log.Error("There was an unexpected error while filtering a list of users from AD.", ex);
                return(Content(HttpStatusCode.InternalServerError, "There was an unexpected error while filtering a list of users from AD."));
            }
        }
Exemplo n.º 3
0
        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."));
            }
        }
Exemplo n.º 4
0
        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."));
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult AddUsertoDB([FromBody] AddPrenoteUserVM filter)
        {
            if (filter == null)
            {
                return(Content(HttpStatusCode.BadRequest, "Request body not valid"));
            }

            try
            {
                var          username = (User.Identity.Name).Split('@')[0].Trim();
                PrenotesUser NewUser  = new PrenotesUser();
                NewUser.Admin       = filter.Admin;
                NewUser.Deleted     = false;
                NewUser.Email       = filter.user.Email;
                NewUser.Manager     = filter.Manager;
                NewUser.Username    = filter.user.Username;
                NewUser.DefaultSite = filter.defaultsite;
                PrenotesUser _User = new PrenotesUser();
                _User = arcodb.PrenotesUsers.Where(a => a.Username == filter.user.Username && a.Deleted == false).FirstOrDefault();
                if (_User != null)
                {
                    if (_User.Username == NewUser.Username)
                    {
                        return(Content(HttpStatusCode.Forbidden, "User Already exists."));
                    }
                }


                NewUser.DisplayName  = filter.user.DisplayName;
                NewUser.CreatedDate  = DateTime.Now;
                NewUser.ModifiedDate = DateTime.Now;
                NewUser.CreatedBy    = username;
                NewUser.ModifiedBy   = username;

                arcodb.PrenotesUsers.Add(NewUser);
                arcodb.SaveChanges();

                UserSiteLocation bridge1 = new UserSiteLocation();
                bridge1.SiteLocationId = filter.defaultsite;
                bridge1.UserId         = NewUser.Id;
                arcodb.UserSiteLocations.Add(bridge1);


                foreach (var id in filter.othersites)
                {
                    if (id.selected == true)
                    {
                        UserSiteLocation bridge = new UserSiteLocation();
                        bridge.SiteLocationId = id.SiteID;
                        bridge.UserId         = NewUser.Id;
                        arcodb.UserSiteLocations.Add(bridge);
                    }
                }



                arcodb.SaveChanges();

                return(Content(HttpStatusCode.OK, "User added successfully"));
            }
            catch (Exception ex)
            {
                Log.Error("There was an unexpected error while filtering a list of users from AD.", ex);
                return(Content(HttpStatusCode.InternalServerError, "There was an unexpected error while filtering a list of users from AD."));
            }
        }