Ejemplo n.º 1
0
        /// <summary>
        /// The Creates entity for PaymentViewModel.
        /// </summary>
        /// <param name="viewModel">The viewModel <see cref="PaymentViewModel"/>.</param>
        /// <returns>The <see cref="SimpleResponse{PaymentViewModel}"/>.</returns>
        public SimpleResponse <PaymentViewModel> Create(PaymentViewModel model)
        {
            var response = new SimpleResponse <PaymentViewModel>();

            try
            {
                var validation = model.Validate();
                if (validation.HasError)
                {
                    return(new SimpleResponse <PaymentViewModel>
                    {
                        Data = model,
                        ResponseCode = BusinessResponseValues.ValidationErrorResult,
                        ResponseMessage = validation.AllValidationMessages
                    });
                }

                using (var context = new PublicDbContext())
                {
                    var entity = Map <PaymentViewModel, Payment>(model);
                    context.Payment.Add(entity);
                    response.ResponseCode = context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode    = BusinessResponseValues.InternalError;
                response.ResponseMessage = "Ekleme iþleminde hata oluþtu.";
                DayLogger.Error(ex);
            }

            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes record by given id value(s).
        /// </summary>
        /// <returns>The <see cref="SimpleResponse"/>.</returns>
        public SimpleResponse Delete(int addressId)
        {
            var response = new SimpleResponse();

            try
            {
                using (var context = new PublicDbContext())
                {
                    var entity = context.Address.SingleOrDefault(q => q.AddressId == addressId);
                    if (entity == null || entity == default(Address))
                    {
                        response.ResponseCode    = BusinessResponseValues.NullEntityValue;
                        response.ResponseMessage = "Kayýt bulunamadý.";
                        return(response);
                    }

                    context.Address.Remove(entity);
                    response.ResponseCode = context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode    = BusinessResponseValues.InternalError;
                response.ResponseMessage = "Silme iþleminde hata oluþtu.";
                DayLogger.Error(ex);
            }

            return(response);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deletes entity for FilmActorViewModel.
        /// </summary>
        /// <param name="viewModel">The viewModel <see cref="FilmActorViewModel"/>.</param>
        /// <returns>The <see cref="SimpleResponse"/>.</returns>
        public SimpleResponse Delete(FilmActorViewModel model)
        {
            var response = new SimpleResponse();

            try
            {
                using (var context = new PublicDbContext())
                {
                    var entity = context.FilmActor.FirstOrDefault(q => q.ActorId == model.ActorId && q.FilmId == model.FilmId);
                    if (entity == null || entity == default(FilmActor))
                    {
                        response.ResponseCode    = BusinessResponseValues.NullEntityValue;
                        response.ResponseMessage = "Kayýt bulunamadý.";
                        return(response);
                    }

                    context.FilmActor.Remove(entity);
                    response.ResponseCode = context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode    = BusinessResponseValues.InternalError;
                response.ResponseMessage = "Silme iþleminde hata oluþtu.";
                DayLogger.Error(ex);
            }

            return(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Updates entity for AddressViewModel.
        /// </summary>
        /// <param name="viewModel">The viewModel <see cref="AddressViewModel"/>.</param>
        /// <returns>The <see cref="SimpleResponse"/>.</returns>
        public SimpleResponse Update(AddressViewModel model)
        {
            var response = new SimpleResponse();

            try
            {
                var validation = model.Validate();
                if (validation.HasError)
                {
                    return(new SimpleResponse
                    {
                        ResponseCode = BusinessResponseValues.ValidationErrorResult,
                        ResponseMessage = validation.AllValidationMessages
                    });
                }

                using (var context = new PublicDbContext())
                {
                    var entity = context.Address.SingleOrDefault(q => q.AddressId == model.AddressId);
                    if (entity == null || entity == default(Address))
                    {
                        response.ResponseCode    = BusinessResponseValues.NullEntityValue;
                        response.ResponseMessage = "Kayýt bulunamadý.";
                        return(response);
                    }

                    MapTo(model, entity);
                    // context.Address.Attach(entity);
                    // context.Entry(entity).State = EntityState.Modified;
                    response.ResponseCode = context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode    = BusinessResponseValues.InternalError;
                response.ResponseMessage = "Güncelleme iþleminde hata oluþtu.";
                DayLogger.Error(ex);
            }

            return(response);
        }