Exemplo n.º 1
0
        public Infrastructure.ApiResponse <Services.ViewModel.EspecialistViewModel> Post([FromBody] Services.ViewModel.EspecialistViewModel model)
        {
            var response = new Infrastructure.ApiResponse <Services.ViewModel.EspecialistViewModel>();

            try{
                var req = new Services.Message.AddEspecialistRequest();
                req.especialist = model;
                _especialistService.AddEspecialist(req);

                response.status = true;
                response.data   = model;
                response.code   = System.Net.HttpStatusCode.Created;
            }catch (Infrastructure.BusinessRuleException bex) {
                response.status        = true;
                response.code          = System.Net.HttpStatusCode.BadRequest;
                response.brokenRules   = bex.BrokenRules;
                response.error_message = bex.Message;
            }catch (Exception ex) {
                response.status        = true;
                response.code          = System.Net.HttpStatusCode.InternalServerError;
                response.error_message = "Ocorreu um erro inesperado. Entre em contato com o nosso time de desenvolvimento.";
            }
            return(response);
        }
Exemplo n.º 2
0
        public Infrastructure.ApiResponse <Services.ViewModel.EspecialistViewModel> Put(string id, [FromBody] Services.ViewModel.EspecialistViewModel model)
        {
            var response = new Infrastructure.ApiResponse <Services.ViewModel.EspecialistViewModel>();

            try{
                Guid especialistid = Guid.Empty;
                if (!Guid.TryParse(id, out especialistid))
                {
                    return(CreateResponse <Services.ViewModel.EspecialistViewModel>(false, "projeto não encontrado", null, System.Net.HttpStatusCode.NotFound));
                }

                model.Id = especialistid;
                _especialistService.UpdateEspecialist(new Services.Message.UpdateEspecialistRequest()
                {
                    especialist = model
                });

                response.status = true;
                response.data   = model;
                response.code   = System.Net.HttpStatusCode.Created;
            }catch (Infrastructure.BusinessRuleException bex) {
                response.status        = true;
                response.code          = System.Net.HttpStatusCode.BadRequest;
                response.brokenRules   = bex.BrokenRules;
                response.error_message = bex.Message;
            }catch (Exception ex) {
                response.status        = true;
                response.code          = System.Net.HttpStatusCode.InternalServerError;
                response.error_message = "Ocorreu um erro inesperado. Entre em contato com o nosso time de desenvolvimento.";
            }

            return(response);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Detail([Bind("Id,name,charge,image,schoolId")] Services.ViewModel.EspecialistViewModel model, ICollection <IFormFile> files, [Bind("x,y,w,h")] Backend.ViewModel.SizeModel sizeModel)
        {
            var uploads = Path.Combine(_environment.WebRootPath, "images/specialists");

            if (files != null)
            {
                foreach (var file in files)
                {
                    if (file.Length > 0)
                    {
                        var fileextension = Path.GetExtension(file.FileName);
                        var filename      = Guid.NewGuid().ToString() + fileextension;
                        model.image = filename;

                        using (var fileStream = new FileStream(Path.Combine(uploads, filename), FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }

                        //Cortar imagem
                        Rectangle cropRect = new Rectangle(sizeModel.x, sizeModel.y, sizeModel.w, sizeModel.h);
                        Bitmap    src      = System.Drawing.Image.FromFile(Path.Combine(uploads, filename)) as Bitmap;
                        Bitmap    target   = new Bitmap(cropRect.Width, cropRect.Height);

                        using (Graphics g = Graphics.FromImage(target))
                        {
                            g.DrawImage(src,
                                        new Rectangle(0, 0, target.Width, target.Height),
                                        cropRect, GraphicsUnit.Pixel);
                        }

                        using (var fileStream = new FileStream(Path.Combine(uploads, "crp_" + filename), FileMode.Create))
                        {
                            await file.CopyToAsync(fileStream);
                        }
                    }
                }
            }

            Infrastructure.ApiResponse <EscolaDeVoce.Services.ViewModel.EspecialistViewModel> response = null;
            System.Net.Http.HttpMethod method = System.Net.Http.HttpMethod.Post;
            string url = Helpers.EscolaDeVoceEndpoints.Especialists.get;

            if (model.Id != Guid.Empty)
            {
                url   += "/" + model.Id.ToString();
                method = System.Net.Http.HttpMethod.Put;
            }

            response = await ApiRequestHelper.postPutRequest <Infrastructure.ApiResponse <EscolaDeVoce.Services.ViewModel.EspecialistViewModel> >(
                url,
                method,
                JsonConvert.SerializeObject(model)
                );

            if ((method == System.Net.Http.HttpMethod.Post && response.data != null && response.data.Id != Guid.Empty) || model.Id != Guid.Empty)
            {
                Guid Id = model.Id != Guid.Empty ? model.Id : response.data.Id;
                return(RedirectToAction("Detail", new { id = Id.ToString() }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }