internal async Task <ReturnRepository> Update(EstablishmmentModelData establishmentModelData)
        {
            try
            {
                _context.Entry(establishmentModelData).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(ReturnRepository.Create(false, string.Format("Estabelecimento {0} alterado com sucesso!", establishmentModelData.Name)));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (Exists(establishmentModelData.Id))
                {
                    return(ReturnRepository.Create(true, string.Format("Erro ao salvar o estabelecimento {0}!\n Analise o erro: {1}", establishmentModelData.Name, ex.Message)));
                }
                return(ReturnRepository.Create(true, string.Format("ERRO: Este Estabelecimento não existe: {0}", ex.Message)));
            }
        }
Exemple #2
0
        public static EstablishmmentById ToEstablishmmentById(this EstablishmmentModelData data)
        {
            var establishmment = EstablishmmentById.Create(
                data.Id.ToString(),
                data.Name,
                string.Join(", ", data.Address.Street, data.Address.Number, data.Address.State, data.Address.Coutry, data.Address.Zipcode),
                data.Email,
                data.Phone,
                data.TimeOpen,
                data.TimeClose);

            var desWifi = "";

            switch (data.Wifi)
            {
            case 0:
                desWifi = "não tem";
                break;

            case 1:
                desWifi = "fraco";
                break;

            case 2:
                desWifi = "médio";
                break;

            case 3:
                desWifi = "forte";
                break;

            default:
                desWifi = "";
                break;
            }

            var desNoise = "";

            switch (data.Noise)
            {
            case 0:
                desNoise = "não tem";
                break;

            case 1:
                desNoise = "pouco";
                break;

            case 2:
                desNoise = "médio";
                break;

            case 3:
                desNoise = "muito";
                break;

            default:
                desWifi = "";
                break;
            }

            var desPlug = "";

            switch (data.Plug)
            {
            case 0:
                desPlug = "não tem";
                break;

            case 1:
                desPlug = "pouco";
                break;

            case 2:
                desPlug = "alguns";
                break;

            case 3:
                desPlug = "vários";
                break;

            default:
                desWifi = "";
                break;
            }


            establishmment.SetCharacteristics(Characteristic.Create(data.Wifi, desWifi),
                                              Characteristic.Create(data.Noise, desNoise),
                                              Characteristic.Create(data.Plug, desPlug));
            data.Photos.ForEach(x => establishmment.AddPhoto(x.UrlPhoto));

            return(establishmment);
        }
Exemple #3
0
 internal static EstablishmmentToListDisplay ToDisplay(this EstablishmmentModelData data)
 => new EstablishmmentToListDisplay
 {
     Id   = data.Id,
     Name = data.Name
 };
        internal async Task <ReturnRepository> Delete(EstablishmmentModelData establishmentModelData)
        {
            establishmentModelData.Active = false;

            return(await Update(establishmentModelData));
        }