示例#1
0
        public HttpResponseMessage LogoUpload(int custId)
        {
            var customer = _IOrgcustService.GetOrgcusts().Where(p => p.Org.Id == custId).FirstOrDefault();

            try
            {
                foreach (string key in HttpContext.Current.Request.Form.AllKeys)
                {
                    string value = HttpContext.Current.Request.Form[key];
                }

                System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
                string fileName = "";
                byte[] binData  = null;



                for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++)
                {
                    System.Web.HttpPostedFile hpf = hfc[iCnt];

                    if (hpf.ContentLength > 0)
                    {
                        BinaryReader b = new BinaryReader(hpf.InputStream);
                        binData = b.ReadBytes(hpf.ContentLength);

                        fileName = hpf.FileName;
                    }
                }

                customer.Org.Logo = binData;

                _IOrgcustService.UpdateOrgcust(customer);

                return(Request.CreateResponse <string>(HttpStatusCode.OK, "Logo uploaded successfully"));
            }
            catch
            {
                var createresponse = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Logo Upload Failed");
                throw new HttpResponseException(createresponse);
            }
        }
示例#2
0
        public HttpResponseMessage Update(CustomerDTO customerDTO)
        {
            try
            {
                var curDateTime = DateTime.UtcNow;
                var customer    = _IOrgcustService.GetOrgcusts().Where(p => p.Org.Id == customerDTO.Id).FirstOrDefault();
                int userID      = int.Parse(Request.Headers.GetValues("userId").FirstOrDefault());

                if (customer != null)
                {
                    customer.Org.Name            = customerDTO.Name;
                    customer.Org.Descript        = customerDTO.Descript;
                    customer.Org.Comments        = customerDTO.Comments;
                    customer.Org.SOAccountNbr    = customerDTO.CustomerNbr;
                    customer.Org.OtherAccountNbr = customerDTO.OtherAccountNbr;

                    customer.Org.Agreement = customerDTO.Agreement;
                    customer.Org.Logo      = customerDTO.Logo;

                    customer.Org.PromoCode    = customerDTO.PromoCode;
                    customer.Org.BillMe       = customerDTO.BillMe;
                    customer.Org.BillingInfo  = customerDTO.BillingInfo;
                    customer.Org.ImageCleanUp = customerDTO.ImageCleanUp;
                    customer.SLA            = customerDTO.SLA;
                    customer.RemoveBlank    = customerDTO.RemoveBlank;
                    customer.SubmissionOpts = customerDTO.SubmissionOpts;

                    customer.Org.SOW          = customerDTO.SOW;
                    customer.Org.GotAgreement = customerDTO.GotAgreement;

                    customer.Org.ModifiedDate   = DateTime.UtcNow;
                    customer.Org.ModifiedUserId = userID;

                    var locn = _IOrglocnService.GetOrglocns().Where(p => p.Org.Id == customer.Org.Id);
                    if (locn.Count() > 0)
                    {
                        customer.Org.OrgLocns.FirstOrDefault().Locn.AddressLine1 = customerDTO.AddressLine1;
                        customer.Org.OrgLocns.FirstOrDefault().Locn.AddressLine2 = customerDTO.AddressLine2;
                        customer.Org.OrgLocns.FirstOrDefault().Locn.City = customerDTO.City;
                        customer.Org.OrgLocns.FirstOrDefault().Locn.State = customerDTO.State;
                        customer.Org.OrgLocns.FirstOrDefault().Locn.ZipCode = customerDTO.ZipCode;
                    }
                    else
                    {
                        customer.Org.OrgLocns.Add(new OrgLocn()
                        {
                            Org = customer.Org, Locn = new Locn()
                            {
                                AddressLine1 = customerDTO.AddressLine1, AddressLine2 = customerDTO.AddressLine2, City = customerDTO.City, State = customerDTO.State, ZipCode = customerDTO.ZipCode
                            }
                        });
                    }

                    if (customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault() != null)
                    {
                        if (customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().UserId == customerDTO.ContactId)
                        {
                            customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().User.Per.Title = customerDTO.Title;
                        }
                        else
                        {
                            customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().Type = null;
                            customer.Org.OrgUsers.Where(p => p.UserId == customerDTO.ContactId).FirstOrDefault().Type = "Primary";
                            customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().User.Per.Title     = customerDTO.Title;
                        }
                    }
                    else if (customer.Org.OrgUsers.Where(p => p.Type == null).FirstOrDefault() != null)
                    {
                        customer.Org.OrgUsers.Where(p => p.Type == null).FirstOrDefault().UserId         = customerDTO.ContactId;
                        customer.Org.OrgUsers.Where(p => p.Type == null).FirstOrDefault().User.Per.Title = customerDTO.Title;
                        customer.Org.OrgUsers.Where(p => p.Type == null).FirstOrDefault().Type           = "Primary";
                    }

                    if (customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().User.Per.PersContacts.Where(b => b.Contact.ContactTyp.DisplayName == "Phone").Count() > 0)
                    {
                        customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().User.Per.PersContacts.Where(b => b.Contact.ContactTyp.DisplayName == "Phone").FirstOrDefault().Contact.Value = customerDTO.Phone;
                    }
                    else
                    {
                        customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().User.Per.PersContacts.Add(new PersContact()
                        {
                            Per = customer.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().User.Per, Contact = new Contact()
                            {
                                ContactTypId = 2, Value = customerDTO.Phone
                            }
                        });
                    }



                    if (customerDTO.SalesRepId == 0)
                    {
                        if (customer.Org.OrgUsers.Where(p => p.Type == "SalesRep").Count() > 0)
                        {
                            customer.Org.OrgUsers.Remove(customer.Org.OrgUsers.Where(p => p.Type == "SalesRep").FirstOrDefault());
                        }
                    }
                    else if (customer.Org.OrgUsers.Where(p => p.Type == "SalesRep").FirstOrDefault() != null)
                    {
                        customer.Org.OrgUsers.Where(p => p.Type == "SalesRep").FirstOrDefault().UserId = (int)customerDTO.SalesRepId;
                    }
                    else
                    {
                        customer.Org.OrgUsers.Add(new OrgUser()
                        {
                            Org = customer.Org, UserId = (int)customerDTO.SalesRepId, Type = "SalesRep"
                        });
                    }


                    if (customerDTO.CustomerCareId == 0)
                    {
                        if (customer.Org.OrgUsers.Where(p => p.Type == "CustomerCare").Count() > 0)
                        {
                            customer.Org.OrgUsers.Remove(customer.Org.OrgUsers.Where(p => p.Type == "CustomerCare").FirstOrDefault());
                        }
                    }
                    else if (customer.Org.OrgUsers.Where(p => p.Type == "CustomerCare").FirstOrDefault() != null)
                    {
                        customer.Org.OrgUsers.Where(p => p.Type == "CustomerCare").FirstOrDefault().UserId = (int)customerDTO.CustomerCareId;
                    }
                    else
                    {
                        customer.Org.OrgUsers.Add(new OrgUser()
                        {
                            Org = customer.Org, UserId = (int)customerDTO.CustomerCareId, Type = "CustomerCare"
                        });
                    }

                    if (customerDTO.ResellerRepId == 0 || customerDTO.ResellerRepId == null)
                    {
                        if (customer.Org.OrgUsers.Where(p => p.Type == "ResellerRep").Count() > 0)
                        {
                            customer.Org.OrgUsers.Remove(customer.Org.OrgUsers.Where(p => p.Type == "ResellerRep").FirstOrDefault());
                        }
                    }
                    else if (customer.Org.OrgUsers.Where(p => p.Type == "ResellerRep").FirstOrDefault() != null)
                    {
                        customer.Org.OrgUsers.Where(p => p.Type == "ResellerRep").FirstOrDefault().UserId = (int)customerDTO.ResellerRepId;
                    }
                    else
                    {
                        customer.Org.OrgUsers.Add(new OrgUser()
                        {
                            Org = customer.Org, UserId = (int)customerDTO.ResellerRepId, Type = "ResellerRep"
                        });
                    }

                    var OrgStatHist = customer.Org.OrgStatusHists.OrderByDescending(s => s.Id).FirstOrDefault();
                    if (OrgStatHist != null && (OrgStatHist.OrgTypOrgStatu.OrgStatus.DisplayText != customerDTO.StatusName))
                    {
                        var curOrgStatus = _IOrgtyporgstatusService.GetOrgtyporgstatus().Where(p => p.OrgStatus.DisplayText == customerDTO.StatusName).FirstOrDefault();
                        if (curOrgStatus != null)
                        {
                            customer.Org.OrgStatusHists.Add(new OrgStatusHist()
                            {
                                Org = customer.Org, OrgTypOrgStatu = curOrgStatus, CreateDate = DateTime.UtcNow
                            });
                        }
                        if (customerDTO.StatusName == "Active")
                        {
                            customer.Org.ApprovedUserId = userID;
                            customer.Org.ApprovedDate   = DateTime.UtcNow;
                            customer.Org.InactiveUserId = null;
                            customer.Org.InactiveDate   = null;

                            customer.Org.WkflowInstances.FirstOrDefault().WkflowStepHists.Add(new WkflowStepHist
                            {
                                CreateDate    = DateTime.UtcNow,
                                DateLastMaint = DateTime.UtcNow,
                                WkflowStatId  = 1,
                                CreatedUserId = userID
                            });
                        }
                        else if (customerDTO.StatusName == "Suspended")
                        {
                            customer.Org.InactiveUserId = userID;
                            customer.Org.InactiveDate   = DateTime.UtcNow;
                        }
                    }

                    _IOrgcustService.UpdateOrgcust(customer);
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Customer could not be found"));
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }


            return(Request.CreateResponse <bool>(HttpStatusCode.OK, true));
        }