Пример #1
0
        public async Task <HttpResponseMessage> PersonProspectAdd()
        {
            //recebo as imagens se tiver
            try
            {
                var provider = new MultipartMemoryStreamProvider();
                NameValueCollection parameters = HttpContext.Current.Request.Params;
                if (Request.Content.IsMimeMultipartContent())
                {
                    try
                    {
                        await Request.Content.ReadAsMultipartAsync(provider);

                        fs = new List <FIleServer>();
                        int count = 0;
                        foreach (var file in HttpContext.Current.Request.Files)
                        {
                            var    f = provider.Contents[count];
                            string fileName;
                            if (f.Headers.ContentDisposition == null || f.Headers.ContentDisposition.FileName == null)
                            {
                                fileName = parameters["FileName"].ToString();
                            }
                            else
                            {
                                fileName = f.Headers.ContentDisposition.FileName.ToString().Replace("\"", "");
                            }


                            string mimeType      = new MimeType().GetMimeType(fileName);
                            var    stream        = (HttpContext.Current.Request.Files[count]).InputStream;
                            byte[] bytesInStream = new byte[stream.Length];
                            stream.Read(bytesInStream, 0, bytesInStream.Length);

                            Domain.ReadModel.FileTemp ft = new Domain.ReadModel.FileTemp();
                            ft.FileIntegrationCode = Guid.NewGuid();
                            ft.FilePath            = _storage.UploadFile(_containerName, ft.FileIntegrationCode.ToString(), mimeType, bytesInStream);
                            ft.OriginalName        = fileName;
                            try
                            {
                                using (Image img = Image.FromStream(stream: stream,
                                                                    useEmbeddedColorManagement: false,
                                                                    validateImageData: false))
                                {
                                    ft.Width  = img.PhysicalDimension.Width.ToString();
                                    ft.Height = img.PhysicalDimension.Height.ToString();
                                }
                                count++;
                            }
                            catch (Exception ex)
                            {
                                LogManager.Error("Erro ao recuperar dimensoes da imagen", ex);
                            }


                            //salvo na tablea temporaria
                            try
                            {
                                _listFileTemp.Add(_FileTemp.SaveFileTemp(ft));
                            }
                            catch (Exception ex)
                            {
                                LogManager.Info("PersonProspectAdd sem Imagem");
                                throw;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManager.Error(string.Format("PersonProspectAdd image Error:{0}", ex));
                    }
                }



                var Person = new AddPersonCommand()
                {
                    IntegrationCode = Guid.NewGuid(),
                    Name            = parameters["Name"],
                    FantasyName     = parameters["FantasyName"].ToString(),
                    //NameFromSecurityCheck = parameters["NameFromSecurityCheck"].ToString(),
                    //SecuritySourceId =  parameters["SecuritySourceId"],
                    //IsSafe = parameters["IsSafe"],
                    //FriendlyNameURL = parameters["FriendlyNameURL"].ToString(),
                    PersonOriginTypeId = Convert.ToByte(parameters["PersonOriginTypeId"]),
                    //PersonOriginDetails = parameters["PersonOriginDetails"].ToString(),
                    CampaignId      = long.Parse(parameters["CampaignId"].ToString()),
                    CountryId       = Convert.ToByte(parameters["CountryId"]),
                    LanguageId      = Convert.ToByte(parameters["LanguageId"]),
                    PersonTypeId    = Convert.ToByte(parameters["PersonTypeId"]),
                    PersonProfileId = Convert.ToByte(parameters["PersonProfileId"]),
                    PersonStatusId  = Convert.ToByte(parameters["PersonStatusId"]),
                    //PersonalWebSite = parameters["PersonalWebSite.ToString(),
                    CurrencyId      = Convert.ToByte(parameters["CurrencyId"].ToString()),
                    CreationDateUTC = DateTime.UtcNow,
                    //ActivationCode = parameters["ActivationCode.ToString(),
                    //ActivationDateUTC = DateTime.Parse( parameters["ActivationDateUTC"].ToString()),
                    PhoneNumber = parameters["PhoneNumber"].ToString(),
                    //PersonFatherId = parameters["PersonFatherId,
                    InviteId            = long.Parse(parameters["InviteId"].ToString()),
                    ServerInstanceId    = Convert.ToInt16(1),
                    Active              = true,
                    listFileTemp        = _listFileTemp,
                    UserSystemId        = long.Parse(parameters["UserSystem"].ToString()),
                    PersonIntegrationID = Guid.NewGuid()
                                          //,ImgListId = _listFileTemp
                };


                this.bus.Send(Person);


                return(Request.CreateResponse(HttpStatusCode.OK, new { Person.PersonIntegrationID }));
            }
            catch (System.Exception ex)
            {
                LogManager.Error(string.Format("ValidateUser Error:{0}", ex));
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Пример #2
0
        public async Task <HttpResponseMessage> EditPromotionPhoto()
        {
            PromotionPhotoInputDTO promotionPhoto = new PromotionPhotoInputDTO();
            var    provider = new MultipartMemoryStreamProvider();
            Claims claims   = new Claims().Values();
            NameValueCollection parameters = HttpContext.Current.Request.Params;

            try
            {
                if (Request.Content.IsMimeMultipartContent())
                {
                    try
                    {
                        await Request.Content.ReadAsMultipartAsync(provider);

                        fs = new List <FIleServer>();
                        int count = 0;
                        foreach (var file in HttpContext.Current.Request.Files)
                        {
                            var    f = provider.Contents[count];
                            string fileName;
                            if (f.Headers.ContentDisposition == null || f.Headers.ContentDisposition.FileName == null)
                            {
                                fileName = parameters["FileName"].ToString() + ".jpeg";
                            }
                            else
                            {
                                fileName = f.Headers.ContentDisposition.FileName.ToString().Replace("\"", "");
                            }

                            string mimeType      = new MimeType().GetMimeType(fileName);
                            var    stream        = (HttpContext.Current.Request.Files[count]).InputStream;
                            byte[] bytesInStream = new byte[stream.Length];
                            stream.Read(bytesInStream, 0, bytesInStream.Length);

                            Domain.ReadModel.FileTemp ft = new Domain.ReadModel.FileTemp();
                            ft.FileIntegrationCode = Guid.NewGuid();
                            ft.FilePath            = _storage.UploadFile(_containerName, ft.FileIntegrationCode.ToString(), mimeType, bytesInStream);
                            ft.OriginalName        = fileName;
                            try
                            {
                                using (Image img = Image.FromStream(stream: stream,
                                                                    useEmbeddedColorManagement: false,
                                                                    validateImageData: false))
                                {
                                    ft.Width  = img.PhysicalDimension.Width.ToString();
                                    ft.Height = img.PhysicalDimension.Height.ToString();
                                }
                                count++;
                            }
                            catch (Exception ex)
                            {
                                LogManager.Error("Erro ao recuperar dimensoes da imagen", ex);
                            }
                            //salvo na tablea temporaria
                            int fileId = _FileTemp.SaveFileTemp(ft);
                            _listFileTemp.Add(fileId);

                            promotionPhoto.PromotionIntegrationCode = Guid.Parse(parameters["IntegrationCode"].ToString());
                            promotionPhoto.Active       = true;
                            promotionPhoto.FileId       = fileId;
                            promotionPhoto.IsDefault    = true;
                            promotionPhoto.PathImage    = ft.FilePath;
                            promotionPhoto.ShowOrder    = (byte)count;
                            promotionPhoto.UserSystemId = claims.userSystemId;

                            var _clientPromotion = new HttpClient();
                            _clientPromotion.BaseAddress = new Uri(CustomConfiguration.WebApiPromotion);
                            var resultTask = _clientPromotion.PostAsJsonAsync("api/Promotion/EditPromotionPhoto", promotionPhoto).Result;
                            if (!resultTask.IsSuccessStatusCode)
                            {
                                LogManager.Error("EditPromotionPhoto Handler: Erro ao enviar web.api promotion:  status: " + resultTask.StatusCode);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManager.Error(string.Format("PromotionProspectAdd image Error:{0}", ex));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, new { promotionPhoto.PathImage }));
                }
            }
            catch (System.Exception ex)
            {
                LogManager.Error(string.Format("ValidateUser Error:{0} : {1}", ex, ex.StackTrace));
                LogManager.Error(string.Format("ValidateUser Error Parametros recebidos: Alert = {0}, normalPrice =   {1} , discountPercent = {2} ,ExpertiseId =  {3} ,Title =  {4} ,ShortDescription = {5} ,FullDescription = {6} ,StartDateUTC = {7} ,ValidUntilUTC = {8} ,RequiredTimeForActivation = {9},PromotionTypeId = {10} ,PromotionBillingModelId = {11} ,PromotionRecurrenceId = {12} ,PromotionPaymentTypeId = {13} ,CurrencyId = {14} ,ExpertisePromotionCostReferenceId = {15},NumberOfAvailableCoupons = {16} ,PersonIntegrationID = {17}", parameters["Alert"], parameters["NormalPrice"], parameters["DiscountePercentege"], parameters["ExpertiseId"], parameters["Title"], parameters["ShortDescription"], parameters["FullDescription"], parameters["StartDateUTC"], parameters["ValidUntilUTC"], parameters["RequiredTimeForActivation"], parameters["PromotionTypeId"], parameters["PromotionBillingModelId"], parameters["PromotionRecurrenceId"], parameters["PromotionPaymentTypeId"], parameters["CurrencyId"], parameters["ExpertisePromotionCostReferenceId"], parameters["NumberOfAvailableCoupons"], parameters["PersonIntegrationID"].Replace(",", "")));


                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, new { }));
        }
Пример #3
0
        public async Task <HttpResponseMessage> PostFile(string jsonData)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            var json = serializer.Deserialize <dynamic>(jsonData);

            try
            {
                string Name              = json["Name"];
                string Description       = json["Description"];
                string ExpertiseFather   = json["ExpertiseFather"];
                int?   expertiseFatherId = null;
                if (!string.IsNullOrEmpty(ExpertiseFather))
                {
                    expertiseFatherId = int.Parse(ExpertiseFather);
                }
                string ApprovalStatusId = json["ApprovalStatusId"];
                string CreatedBy        = json["CreatedBy"];
                string ApprovedBy       = json["ApprovedBy"];


                //recebo as imagens se tiver
                var provider = new MultipartMemoryStreamProvider();
                if (Request.Content.IsMimeMultipartContent())
                {
                    try
                    {
                        await Request.Content.ReadAsMultipartAsync(provider);

                        fs = new List <FIleServer>();
                        int count = 0;


                        foreach (var f in provider.Contents)
                        {
                            var fileName = f.Headers.ContentDisposition.FileName.ToString().Replace("\"", "");

                            string mimeType = new MimeType().GetMimeType(fileName);

                            var stream = (HttpContext.Current.Request.Files[count]).InputStream;

                            byte[] bytesInStream = new byte[stream.Length];
                            stream.Read(bytesInStream, 0, bytesInStream.Length);

                            Domain.ReadModel.FileTemp ft = new Domain.ReadModel.FileTemp();
                            ft.FileIntegrationCode = Guid.NewGuid();
                            ft.FilePath            = _storage.UploadFile(_containerName, ft.FileIntegrationCode.ToString(), mimeType, bytesInStream);
                            ft.OriginalName        = f.Headers.ContentDisposition.FileName.Replace("\"", "");
                            try
                            {
                                using (Image img = Image.FromStream(stream: stream,
                                                                    useEmbeddedColorManagement: false,
                                                                    validateImageData: false))
                                {
                                    ft.Width  = img.PhysicalDimension.Width.ToString();
                                    ft.Height = img.PhysicalDimension.Height.ToString();
                                }
                                count++;
                            }
                            catch (Exception ex)
                            {
                                LogManager.Error("Erro ao recuperar dimensoes da imagen", ex);
                            }


                            //salvo na tablea temporaria


                            _listFileTemp.Add(_FileTemp.SaveFileTemp(ft));
                        }
                    }
                    catch (Exception ex)
                    {
                        LogManager.Info("Expertise sem Imagem");
                    }
                }


                var user = this._UserDao.Get(new Domain.ReadModel.User {
                    UserId = int.Parse(CreatedBy)
                });



                var expertise = new AddExpertiseCommand()
                {
                    Name = Name,
                    DefaultDescription = Description,
                    ApprovedDate       = DateTime.UtcNow,
                    CreatedDateUTC     = DateTime.UtcNow,
                    ExpertiseFatherId  = expertiseFatherId,
                    ApprovalStatusId   = byte.Parse(ApprovalStatusId),
                    CreatedBy          = int.Parse(CreatedBy),
                    ApprovedBy         = int.Parse(ApprovedBy),
                    Active             = true,
                    listFileTemp       = _listFileTemp,
                    PersonId           = user.PersonId
                };

                this.bus.Send(expertise);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                LogManager.Error("Erro ao cadastrar Expertise: ", ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }