Пример #1
0
        public async Task<ResponseModel<Company>> DeleteCompany(int id)
        {
            ResponseModel<Company> result = new ResponseModel<Company>();
            bool success = await _companiesDal.DeleteCompany(id);
            if (!success)
            {
                result.Errors.Add(new Error()
                {
                    ErrorType = Models.Enums.ErrorTypes.NotFound,
                    ShortMessage = "Фирмата не беше намерена!"
                });
                return result;
            }

            result.Messages.Add("Фирмата беше успешно изтрита");
            return result;
        }
Пример #2
0
        public async Task<ResponseModel<GetCityEntity>> GetCityById(int id)
        {
            ResponseModel<GetCityEntity> result = new ResponseModel<GetCityEntity>();
            GetCityEntity city = await _citiesDal.GetCityById(id);
            if (city == null)
            {
                result.Errors.Add(new Error()
                {
                    ErrorType = ErrorTypes.NotFound,
                    ShortMessage = "The city hasn't been found."
                });
                return result;
            }

            result.Data = city;

            return result;
        }
Пример #3
0
        public async Task<ResponseModel> UpdateCompany(int id, Company company)
        {
            ResponseModel result = new ResponseModel();
            if (id != company.CompanyID)
            {
                result.Errors.Add(new Error()
                {
                    ErrorType = Models.Enums.ErrorTypes.Validation,
                    ShortMessage = "Номерата на компанията на са еднакви!"
                });
                return result;
            }

            try
            {
                bool success = await _companiesDal.UpdateCompany(id, company);
                if (!success)
                {
                    result.Errors.Add(new Error()
                    {
                        ErrorType = Models.Enums.ErrorTypes.NotFound,
                        ShortMessage = "Фирмата не беше намерена!"
                    });
                    return result;
                }

                result.Messages.Add("Данните за фирмата бяха обновени!");
            }
            catch (Exception ex)
            {
                result.Errors.Add(new Error()
                {
                    ErrorType = Models.Enums.ErrorTypes.Exception,
                    ShortMessage = "Възникна проблем със запазването на данните!",
                    LongMessage = ex.Message.ToString()
                });
                return result;
            }

            return result;
        }