Esempio n. 1
0
        public void CustomerTags(int customerId, string tags)
        {
            var        ctx          = new SCMContext();
            var        customer     = ctx.Customers.Find(customerId);
            List <int> tagList      = tags.Split(',').Select(x => Convert.ToInt32(x)).ToList();
            List <int> customerTags = customer.Tags.Select(x => x.Id).ToList();
            List <int> deletedTags  = customerTags.Where(x => !tagList.Contains(x)).ToList();

            if (deletedTags.Count > 0)
            {
                foreach (int i in deletedTags)
                {
                    customer.Tags.Remove(ctx.Tags.Find(i));
                    customerTags.Remove(i);
                }
                ctx.SaveChanges();
            }
            tagList.RemoveAll(x => customerTags.Contains(x));
            if (tagList.Count > 0)
            {
                foreach (int id in tagList)
                {
                    customer.Tags.Add(ctx.Tags.Find(id));
                }
                ctx.SaveChanges();
            }
            Utils.DataManager.ChangeCustomer(customerId);
        }
Esempio n. 2
0
        public void ServiceRequestTags(int requestId, string tags)
        {
            var        ctx         = new SCMContext();
            var        request     = ctx.ServiceRequests.Find(requestId);
            List <int> tagList     = tags.Split(',').Select(x => Convert.ToInt32(x)).ToList();
            List <int> requestTags = request.Tags.Select(x => x.Id).ToList();
            List <int> deletedTags = requestTags.Where(x => !tagList.Contains(x)).ToList();

            if (deletedTags.Count > 0)
            {
                foreach (int i in deletedTags)
                {
                    request.Tags.Remove(ctx.Tags.Find(i));
                    requestTags.Remove(i);
                }
                ctx.SaveChanges();
            }
            tagList.RemoveAll(x => requestTags.Contains(x));
            if (tagList.Count > 0)
            {
                foreach (int id in tagList)
                {
                    request.Tags.Add(ctx.Tags.Find(id));
                }
                ctx.SaveChanges();
            }
            Utils.DataManager.ChangeRequest(requestId);
        }
Esempio n. 3
0
        public void ApplyActive(string idList)
        {
            if (!string.IsNullOrEmpty(idList))
            {
                var ids = new List <int>();
                foreach (var item in idList.Split(','))
                {
                    int id;
                    if (int.TryParse(item, out id))
                    {
                        if (id > 0)
                        {
                            ids.Add(id);
                        }
                    }
                }

                foreach (var item in db.Engineers.Where(x => ids.Contains(x.Id)))
                {
                    item.IsActive = !item.IsActive;
                }
                db.SaveChanges();
                Utils.DataManager.ResetEngineers();
            }
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "Id,Reason")] CancelReason model)
        {
            if (ModelState.IsValid)
            {
                db.CancelReasons.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 5
0
        public ActionResult Create([Bind(Include = "Id,Name,TagType,Format")] Tag model)
        {
            if (ModelState.IsValid)
            {
                db.Tags.Add(model);
                db.SaveChanges();
                Utils.DataManager.ResetTags();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 6
0
        public ActionResult Create([Bind(Include = "Id,Name")] City model)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(model);
                db.SaveChanges();
                Utils.DataManager.ResetCities();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 7
0
        public ActionResult Create([Bind(Include = "Id,Name,CityId")] Region model)
        {
            ViewBag.CityId = Utils.ListManager.GetCities();

            if (ModelState.IsValid)
            {
                db.Regions.Add(model);
                db.SaveChanges();
                Utils.DataManager.ResetRegions();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 8
0
        public ActionResult RequestsDepartmentModifier([Bind(Include = "DepartmentId1,DepartmentId2")] RequestsDepartmentModifier model)
        {
            if (ModelState.IsValid)
            {
                SCMContext ctx         = new SCMContext();
                var        department1 = ctx.Departments.Find(model.DepartmentId1);
                var        department2 = ctx.Departments.Find(model.DepartmentId2);

                var engineers = department1.Engineers.ToList();
                foreach (var e in engineers)
                {
                    e.DepartmentId = department2.Id;
                }

                var requests = department1.ServiceRequests.ToList();
                foreach (var r in requests)
                {
                    r.DepartmentId = department2.Id;
                }

                ctx.SaveChanges();
                Utils.DataManager.ResetDepartments();
                Utils.DataManager.ResetEngineers();
                Utils.DataManager.ResetRequests();
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 9
0
 public ActionResult Edit([Bind(Include = "Id,B2BFlag,CompletionDate,InputDate,PullingDate,Dealer,DealerName,DealerReceiptNo,ASCRemarks,SchComplaintDate,SchComplaintCount,SchComplaintRemarks,ASCClaimNo,EsnImeiNo,OutModel,ReceiptDate,TransferSendDate,TransferReceiptDate,FirstPromiseDate,Schedule,PromiseDate,Schedule1,DelayFromPromiseDate,DelayFromReceiptDate,TransferApprovalDate")] ExServiceRequest exServiceRequest)
 {
     if (ModelState.IsValid)
     {
         db.Entry(exServiceRequest).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Edit", "ServiceRequests", new { id = exServiceRequest.Id }));
     }
     ViewBag.Id = new SelectList(db.ServiceRequests, "Id", "RQN", exServiceRequest.Id);
     return(View(exServiceRequest));
 }
Esempio n. 10
0
        public ActionResult CustomerMerge([Bind(Include = "CustomerId1,CustomerId2")] CustomerMerge model)
        {
            if (ModelState.IsValid)
            {
                SCMContext ctx       = new SCMContext();
                var        customer1 = ctx.Customers.Find(model.CustomerId1);
                var        customer2 = ctx.Customers.Find(model.CustomerId2);

                if (string.IsNullOrEmpty(customer2.Phone))
                {
                    customer2.Phone = customer1.Phone;
                }
                if (string.IsNullOrEmpty(customer2.Mobile))
                {
                    customer2.Mobile = customer1.Mobile;
                }
                if (!customer2.CityId.HasValue)
                {
                    customer2.CityId = customer1.CityId;
                }
                if (!customer2.RegionId.HasValue)
                {
                    customer2.RegionId = customer1.RegionId;
                }
                if (string.IsNullOrEmpty(customer2.Address))
                {
                    customer2.Address = customer1.Address;
                }
                if (string.IsNullOrEmpty(customer2.Comments))
                {
                    customer2.Comments = customer1.Comments;
                }

                var requests = customer1.ServiceRequests.ToList();
                foreach (var r in requests)
                {
                    r.CustomerId = customer2.Id;
                }

                var tags = customer1.Tags.ToList();
                foreach (var t in tags)
                {
                    if (!t.Customers.Contains(customer2))
                    {
                        t.Customers.Add(customer2);
                    }
                }
                ctx.SaveChanges();

                Utils.DataManager.ResetCustomers();
                Utils.DataManager.ResetRequests();
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 11
0
        public ActionResult Create([Bind(Include = "Id,Name,Phone,Mobile,CityId,RegionId,Address,IsBlackListed,Comments")] Customer model)
        {
            ViewBag.CityId   = Utils.ListManager.GetCities();
            ViewBag.RegionId = Utils.ListManager.GetRegions();

            if (ModelState.IsValid)
            {
                db.Customers.Add(model);
                db.SaveChanges();
                Utils.DataManager.AddCustomer(model.Id);
                if (TempData["ForwardToRequests"] != null && ((bool)TempData["ForwardToRequests"]) == true)
                {
                    return(RedirectToAction("Create", "ServiceRequests", new { customerId = model.Id }));
                }
                else
                {
                    return(RedirectToAction("Edit", new { id = model.Id }));
                }
            }

            return(View(model));
        }
Esempio n. 12
0
        private void ImportCancelReasons(SCMContext ctx, ref IEnumerable <ServiceRequestRecord> data)
        {
            ResetProgress();

            var curList = ctx.CancelReasons.Select(x => x.Reason).ToList();
            var dic     = new Dictionary <string, CancelReason>();
            var objects = data.Select(x => new { Reason = x.Cancel_Reason }).Distinct().Where(x => !string.IsNullOrEmpty(x.Reason)).ToList();

            var objectToAdd = objects.Where(x => !curList.Contains(x.Reason));

            total = objectToAdd.Count();
            foreach (var item in objectToAdd)
            {
                var rec = new CancelReason()
                {
                    Reason = item.Reason
                };
                ctx.CancelReasons.Add(rec);
                ctx.SaveChanges();
                if (!dic.ContainsKey(rec.Reason.ToUpper()))
                {
                    dic.Add(rec.Reason.ToUpper(), rec);
                }

                UpdateProgress();
            }
            foreach (var item in ctx.CancelReasons)
            {
                if (!dic.ContainsKey(item.Reason.ToUpper()))
                {
                    dic.Add(item.Reason.ToUpper(), item);
                }
            }
            foreach (var item in data)
            {
                if (!string.IsNullOrEmpty(item.Cancel_Reason))
                {
                    item.CancelReasonId = dic[item.Cancel_Reason.ToUpper()].Id;
                }
                else
                {
                    item.CancelReasonId = null;
                }
            }

            Progress = 100;
        }
Esempio n. 13
0
        private void ImportEngineers(SCMContext ctx, ref IEnumerable <ServiceRequestRecord> data)
        {
            ResetProgress();

            var curList      = ctx.Engineers.Select(x => x.Name).ToList();
            var dic          = new Dictionary <string, Engineer>();
            var objects      = data.Select(x => new { Name = x.SVC_Engineer_Name }).Distinct().Where(x => !string.IsNullOrEmpty(x.Name)).ToList();
            var objectsToAdd = objects.Where(x => !curList.Contains(x.Name));

            total = objectsToAdd.Count();

            foreach (var item in objectsToAdd)
            {
                var rec = new Engineer()
                {
                    Name = item.Name, DepartmentId = 1, IsActive = true
                };
                ctx.Engineers.Add(rec);
                ctx.SaveChanges();
                if (!dic.ContainsKey(rec.Name.ToUpper()))
                {
                    dic.Add(rec.Name.ToUpper(), rec);
                }

                UpdateProgress();
            }
            foreach (var item in ctx.Engineers)
            {
                if (!dic.ContainsKey(item.Name.ToUpper()))
                {
                    dic.Add(item.Name.ToUpper(), item);
                }
            }
            foreach (var item in data)
            {
                if (!string.IsNullOrEmpty(item.SVC_Engineer_Name))
                {
                    item.EngineerId = dic[item.SVC_Engineer_Name.ToUpper()].Id;
                }
                else
                {
                    item.EngineerId = null;
                }
            }

            Progress = 100;
        }
Esempio n. 14
0
        public ActionResult RequestsProductModifier([Bind(Include = "ProductId1,ProductId2")] RequestsProductModifier model)
        {
            if (ModelState.IsValid)
            {
                SCMContext ctx      = new SCMContext();
                var        product1 = ctx.Products.Find(model.ProductId1);
                var        product2 = ctx.Products.Find(model.ProductId2);

                var requests = product1.ServiceRequests.ToList();
                foreach (var r in requests)
                {
                    r.ProductId = product2.Id;
                }

                ctx.SaveChanges();
                Utils.DataManager.ResetRequests();
            }
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 15
0
        private void ImportProducts(SCMContext ctx, ref IEnumerable <ServiceRequestRecord> data)
        {
            ResetProgress();

            var curList      = ctx.Products.Select(x => x.Id.ToUpper()).ToList();
            var dic          = new Dictionary <string, Product>();
            var objects      = data.Select(x => new { Id = x.Service_Product_Code, Name = x.SVC_Product.Trim(), IsActive = true }).Distinct().Where(x => !string.IsNullOrEmpty(x.Id)).ToList();
            var objectsToAdd = objects.Where(x => !curList.Contains(x.Id.ToUpper()));

            total = objectsToAdd.Count();
            foreach (var item in objectsToAdd)
            {
                var rec = new Product()
                {
                    Id = item.Id, Name = item.Name.Trim(), IsActive = item.IsActive
                };
                ctx.Products.Add(rec);
                ctx.SaveChanges();
                if (!dic.ContainsKey(rec.Id.ToUpper()))
                {
                    dic.Add(rec.Id.ToUpper(), rec);
                }
                UpdateProgress();
            }
            foreach (var item in ctx.Products)
            {
                if (!dic.ContainsKey(item.Id.ToUpper()))
                {
                    dic.Add(item.Id.ToUpper(), item);
                }
            }
            foreach (var item in data)
            {
                item.ProductId = item.Service_Product_Code.ToUpper();
            }
            Progress = 100;
        }
Esempio n. 16
0
        private void ImportCustomers(SCMContext ctx, ref IEnumerable <ServiceRequestRecord> data)
        {
            ResetProgress();

            var curList = ctx.Customers.Select(x => x.Name).ToList();
            var dic     = new Dictionary <string, Customer>();
            var tags    = ctx.Tags.Where(x => x.TagType == "C").ToDictionary(x => x.Name, y => y);
            var objects = data.Select(x => new { Name = x.Customer_Name, Phone = x.Customer_Phone_No, Mobile = x.Cellular_No, City = x.CityId, Address = x.Address, CustomerType = x.Customer_Type }).Distinct().Where(x => !string.IsNullOrEmpty(x.Name)).ToList();

            var objectsToAdd = objects.Where(x => !curList.Contains(x.Name));

            total = objectsToAdd.Count();
            foreach (var item in objectsToAdd)
            {
                var rec = new Customer()
                {
                    Name = item.Name, Phone = item.Phone, Mobile = item.Mobile, CityId = item.City, Address = item.Address
                };
                if (string.IsNullOrEmpty(rec.Phone) && string.IsNullOrEmpty(rec.Mobile))
                {
                    rec.Phone = "011XXXX";
                }
                ctx.Customers.Add(rec);
                ctx.SaveChanges();
                if (!dic.ContainsKey(rec.Name.ToUpper()))
                {
                    dic.Add(rec.Name.ToUpper(), rec);
                }

                // Add Customer Tags
                string t1 = item.CustomerType;
                if (t1 == "General Enduser")
                {
                    t1 = "General End User";
                }
                Tag t = null;
                if (!tags.ContainsKey(t1))
                {
                    t = new Tag()
                    {
                        Name = t1, TagType = "C", Format = "label-default"
                    };
                    ctx.Tags.Add(t);
                    ctx.SaveChanges();
                    tags.Add(t.Name, t);
                }
                else
                {
                    t = tags[t1];
                }
                if (t != null)
                {
                    rec.Tags.Add(t);
                    ctx.SaveChanges();
                }

                UpdateProgress();
            }
            foreach (var item in ctx.Customers)
            {
                if (!dic.ContainsKey(item.Name.ToUpper()))
                {
                    dic.Add(item.Name.ToUpper(), item);
                }
            }
            ResetProgress();
            total = data.Count();
            foreach (var item in data)
            {
                if (!string.IsNullOrEmpty(item.Customer_Name) && dic.ContainsKey(item.Customer_Name))
                {
                    item.CustomerId = dic[item.Customer_Name.ToUpper()].Id;
                }
                UpdateProgress();
            }

            Progress = 100;
        }
Esempio n. 17
0
        public ActionResult Create([Bind(Include = "Id,CustomerId,RequestDate,StatusId,StatusDate,CenterId,RQN,ReceiptNo,DepartmentId,ProductId,Model,SN,EngineerId,Description,Remarks,ClosingDate,PendingReasonId,CancelReasonId,CreatedBy,CreatedOn,UpdatedBy,UpdatedOn,IsDeleted")] ServiceRequest model)
        {
            //Set default values
            model.CenterId = 1;
            model.StatusId = 10;
            if (model.RequestDate >= DateTime.Now)
            {
                model.StatusDate = model.RequestDate;
            }
            else
            {
                model.StatusDate = DateTime.Now;
            }

            if (string.IsNullOrEmpty(User.Identity.Name))
            {
                model.CreatedBy = "SYSTEM";
                model.UpdatedBy = "SYSTEM";
            }
            else
            {
                model.CreatedBy = User.Identity.Name;
                model.UpdatedBy = User.Identity.Name;
            }
            model.CreatedOn = DateTime.Now;
            model.UpdatedOn = DateTime.Now;


            if (ModelState.IsValid)
            {
                try
                {
                    db.ServiceRequests.Add(model);
                    db.SaveChanges();
                    var exRequest = db.ExServiceRequests.Create();
                    exRequest.Id = model.Id;
                    db.ExServiceRequests.Add(exRequest);
                    db.SaveChanges();
                    DataManager.AddRequest(model.Id);
                }
                catch (Exception e)
                {
                    throw e;
                }

                return(RedirectToAction("Edit", new { id = model.Id }));
            }

            ViewBag.CenterId     = new SelectList(DataManager.Centers(), "Id", "Name");
            ViewBag.DepartmentId = new SelectList(DataManager.Departments(), "Id", "Name");
            // get active products
            //var products = DataManager.Products().Where(x => x.Id == model.ProductId || x.IsActive);
            ViewBag.ProductId = Utils.ListManager.GetProducts();
            // new SelectList(products, "Id", "Name", model.ProductId);

            // get active engineers
            // var engineers = DataManager.Engineers().Where(x => x.Id == model.EngineerId || (x.DepartmentId == model.DepartmentId && x.IsActive));
            ViewBag.EngineerId = Utils.ListManager.GetEngineers(model.DepartmentId);
            // new SelectList(engineers, "Id", "Name", model.EngineerId);

            return(View(model));
        }