コード例 #1
0
        public void UpdateOrganization(int merId, string user)
        {
            var credentials = (from u in _db.Users
                               where u.Id == user
                               select new { MerUser = u.MerUserUsername, MerPass = u.MerUserPassword }).First();
            var organization = _db.Organizations.Find(merId);

            using (var mer = new WebClient()
            {
                Encoding = Encoding.UTF8
            })
            {
                MerApiGetSubjekt request = new MerApiGetSubjekt()
                {
                    Id         = credentials.MerUser,
                    Pass       = credentials.MerPass,
                    Oib        = "99999999927",
                    PJ         = "",
                    SoftwareId = "MojCRM-001",
                    SubjektPJ  = organization.MerId.ToString()
                };

                string merRequest = JsonConvert.SerializeObject(request);

                mer.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                mer.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8");
                var response =
                    mer.UploadString(new Uri(App.MerEndpoint + @"apis/v21/getSubjektData").ToString(), "POST",
                                     merRequest);
                response = response.Replace("[", "").Replace("]", "");
                MerGetSubjektDataResponse result = JsonConvert.DeserializeObject <MerGetSubjektDataResponse>(response);

                string postalCode = result.Mjesto.Substring(0, 5).Trim();
                string mainCity   = result.Mjesto.Substring(6).Trim();

                organization.SubjectName     = result.Naziv;
                organization.FirstReceived   = result.FirstReceived;
                organization.FirstSent       = result.FirstSent;
                organization.ServiceProvider = (ServiceProviderEnum)result.ServiceProviderId;
                organization.UpdateDate      = DateTime.Now;
                organization.LastUpdatedBy   = "Moj-CRM - ImportContract";
                organization.MerUpdateDate   = DateTime.Now;
                organization.OrganizationDetail.MainAddress              = result.Adresa;
                organization.OrganizationDetail.MainPostalCode           = Int32.Parse(postalCode);
                organization.OrganizationDetail.MainCity                 = mainCity;
                organization.OrganizationDetail.CorrespondenceAddress    = result.Adresa;
                organization.OrganizationDetail.CorrespondencePostalCode = Int32.Parse(postalCode);
                organization.OrganizationDetail.CorrespondenceCity       = mainCity;
                organization.MerDeliveryDetail.TotalSent                 = result.TotalSent;
                organization.MerDeliveryDetail.TotalReceived             = result.TotalReceived;
            }
            _db.SaveChanges();
        }
コード例 #2
0
        public void UpdateOrganization(int merId)
        {
            var organization = _db.Organizations.First(o => o.MerId == merId);

            using (var mer = new WebClient {
                Encoding = Encoding.UTF8
            })
            {
                MerApiGetSubjekt request = new MerApiGetSubjekt
                {
                    Id         = "12619",
                    Pass       = _db.Users.Where(x => x.MerUserUsername == "12619").Select(x => x.MerUserPassword).First(),
                    Oib        = "99999999927",
                    PJ         = "",
                    SoftwareId = "MojCRM-001",
                    SubjektPJ  = organization.MerId.ToString()
                };

                string merRequest = JsonConvert.SerializeObject(request);

                mer.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                mer.Headers.Add(HttpRequestHeader.AcceptCharset, "utf-8");
                var response =
                    mer.UploadString(new Uri(App.MerEndpoint + @"apis/v21/getSubjektData").ToString(), "POST",
                                     merRequest);
                response = response.Replace("[", "").Replace("]", "");
                MerGetSubjektDataResponse result = JsonConvert.DeserializeObject <MerGetSubjektDataResponse>(response);

                organization.SubjectName                     = result.Naziv;
                organization.FirstReceived                   = result.FirstReceived;
                organization.FirstSent                       = result.FirstSent;
                organization.ServiceProvider                 = (ServiceProviderEnum)result.ServiceProviderId;
                organization.UpdateDate                      = DateTime.Now;
                organization.LastUpdatedBy                   = "Moj-CRM - UpdateTotalSentAndReceived";
                organization.MerUpdateDate                   = DateTime.Now;
                organization.MerDeliveryDetail.TotalSent     = result.TotalSent;
                organization.MerDeliveryDetail.TotalReceived = result.TotalReceived;
            }
            _db.SaveChanges();
        }