Esempio n. 1
0
        public HttpResponseMessage Reseller(int resellerId)
        {
            ResellerDTO search = null;

            var reseller = _IOresellerService.GetOrgresellers().Where(p => p.Org.Id == resellerId).FirstOrDefault();

            if (reseller != null)
            {
                search = PlatformMappingHelper.Map <OrgReseller, ResellerDTO>(reseller);

                if (search == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Reseller could not be found"));
            }

            return(Request.CreateResponse <ResellerDTO>(HttpStatusCode.OK, search));
        }
Esempio n. 2
0
        public HttpResponseMessage Update(ResellerDTO ResellerDTO)
        {
            try
            {
                var curDateTime = DateTime.UtcNow;
                var reseller    = _IOresellerService.GetOrgreseller(ResellerDTO.Id);
                int userID      = int.Parse(Request.Headers.GetValues("userId").FirstOrDefault());

                if (reseller != null)
                {
                    reseller.Org.Name         = ResellerDTO.Name;
                    reseller.Org.Descript     = ResellerDTO.Descript;
                    reseller.Org.SOAccountNbr = ResellerDTO.SOAccountNbr;

                    reseller.Org.Agreement = ResellerDTO.Agreement;
                    reseller.Org.Logo      = ResellerDTO.Logo;

                    reseller.Org.BillMe       = ResellerDTO.BillMe;
                    reseller.Org.BillingInfo  = ResellerDTO.BillingInfo;
                    reseller.Org.SOW          = ResellerDTO.SOW;
                    reseller.Org.GotAgreement = ResellerDTO.GotAgreement;

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

                    reseller.Org.OrgLocns.FirstOrDefault().Locn.AddressLine1 = ResellerDTO.AddressLine1;
                    reseller.Org.OrgLocns.FirstOrDefault().Locn.AddressLine2 = ResellerDTO.AddressLine2;
                    reseller.Org.OrgLocns.FirstOrDefault().Locn.City = ResellerDTO.City;
                    reseller.Org.OrgLocns.FirstOrDefault().Locn.State = ResellerDTO.State;
                    reseller.Org.OrgLocns.FirstOrDefault().Locn.ZipCode = ResellerDTO.ZipCode;

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


                    if (reseller.Org.OrgUsers.Where(p => p.Type == "SalesRep").FirstOrDefault() != null)
                    {
                        reseller.Org.OrgUsers.Where(p => p.Type == "SalesRep").FirstOrDefault().UserId = ResellerDTO.SalesRepId;
                    }

                    if (reseller.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().User.Per.PersContacts.Where(b => b.Contact.ContactTyp.DisplayName == "Phone") != null)
                    {
                        reseller.Org.OrgUsers.Where(p => p.Type == "Primary").FirstOrDefault().User.Per.PersContacts.Where(b => b.Contact.ContactTyp.DisplayName == "Phone").FirstOrDefault().Contact.Value = ResellerDTO.Phone;
                    }

                    if (reseller.Org.OrgStatusHists.OrderByDescending(s => s.Id).FirstOrDefault().OrgTypOrgStatu.Id != ResellerDTO.StatusID)
                    {
                        reseller.Org.OrgStatusHists.OrderByDescending(s => s.Id).FirstOrDefault().OrgTypOrgStatusId = ResellerDTO.StatusID;
                        if (ResellerDTO.StatusName == "Active")
                        {
                            reseller.Org.ApprovedUserId = userID;
                            reseller.Org.ApprovedDate   = DateTime.UtcNow;
                            reseller.Org.InactiveUserId = null;
                            reseller.Org.InactiveDate   = null;
                        }
                        else if (ResellerDTO.StatusName == "Suspended")
                        {
                            reseller.Org.InactiveUserId = userID;
                            reseller.Org.InactiveDate   = DateTime.UtcNow;
                        }
                    }

                    _IOresellerService.UpdateOrgreseller(reseller);
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "reseller could not be found"));
                }
            }
            catch (Exception e)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }


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