/// <summary>
        /// The Reads for LanguageViewModel.
        /// </summary>
        /// <returns>The <see cref="SimpleResponse{LanguageViewModel}"/>.</returns>
        public SimpleResponse <LanguageViewModel> Read(int languageId)
        {
            var response = new SimpleResponse <LanguageViewModel>();

            try
            {
                using (var context = new PublicCoreDbContext())
                {
                    var entity = context.Language
                                 .AsNoTracking()
                                 .FirstOrDefault(q => q.LanguageId == languageId);

                    if (entity == null || entity == default(Language))
                    {
                        response.ResponseCode    = BusinessResponseValues.NullEntityValue;
                        response.ResponseMessage = "Kayýt bulunamadý.";
                        return(response);
                    }

                    response.Data         = Map <Language, LanguageViewModel>(entity);
                    response.ResponseCode = 1;
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode    = BusinessResponseValues.InternalError;
                response.ResponseMessage = "Okuma iþleminde hata oluþtu.";
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #2
0
        /// <summary>
        /// Reads All records for PaymentViewModel.
        /// </summary>
        /// <returns>The <see cref="SimpleResponse{List{PaymentViewModel}}"/>.</returns>
        public SimpleResponse <List <PaymentViewModel> > ReadAll()
        {
            var response = new SimpleResponse <List <PaymentViewModel> >();

            try
            {
                using (var context = new PublicDbContext())
                {
                    var entities = context.Payment
                                   .AsNoTracking()
                                   .ToList() ?? new List <Payment>();

                    response.Data         = MapList <Payment, PaymentViewModel>(entities);
                    response.ResponseCode = response.Data.Count;
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode    = BusinessResponseValues.InternalError;
                response.ResponseMessage = "Okuma iþleminde hata oluþtu.";
                DayLogger.Error(ex);
            }

            response.Data = response.Data ?? new List <PaymentViewModel>();
            return(response);
        }
        public override SimpleResponse <LongCommandResult> Handle(CategoryUpdateCommand command)
        {
            var response = new SimpleResponse <LongCommandResult>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var result = connection.PartialUpdate <CategoryEntity>(new
                        {
                            command.Name
                        }, p => p.CategoryId == command.CategoryId);
                        response.ResponseCode = result;
                        response.RCode        = result.ToString();
                        response.Data         = new LongCommandResult {
                            ReturnValue = command.CategoryId
                        };
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #4
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);
        }
        /// <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);
        }
Example #6
0
        /// <summary>
        /// The Reads for AddressViewModel.
        /// </summary>
        /// <returns>The <see cref="SimpleResponse{AddressViewModel}"/>.</returns>
        public SimpleResponse <AddressViewModel> Read(int addressId)
        {
            var response = new SimpleResponse <AddressViewModel>();

            try
            {
                using (var context = new PublicDbContext())
                {
                    var entity = context.Address
                                 .AsNoTracking()
                                 .SingleOrDefault(q => q.AddressId == addressId);

                    if (entity == null || entity == default(Address))
                    {
                        response.ResponseCode    = BusinessResponseValues.NullEntityValue;
                        response.ResponseMessage = "Kayýt bulunamadý.";
                        return(response);
                    }

                    response.Data         = Map <Address, AddressViewModel>(entity);
                    response.ResponseCode = 1;
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode    = BusinessResponseValues.InternalError;
                response.ResponseMessage = "Okuma iþleminde hata oluþtu.";
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #7
0
        public override SimpleResponse <FilmList> Handle(FilmReadAllQuery query)
        {
            var response = new SimpleResponse <FilmList>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var FilmEntList = connection.GetAll <FilmEntity>();
                        // var result = connection.QueryList<Syp.Entity.ServiceDetailType>("select * from service_detail_type where is_deleted = false and lower(detail_type_name) like '%' || :name || '%'", new { name = query.Name.ToLowerInvariant() });
                        response.Data = new FilmList
                        {
                            Films = FilmEntList.Select(p => Map <FilmEntity, FilmViewModel>(p)).ToList() ?? new List <FilmViewModel>()
                        };
                        response.ResponseCode = response.Data?.Films?.Count ?? 0;
                        response.RCode        = response.ResponseCode.ToString();
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #8
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);
        }
        public override SimpleResponse <LongCommandResult> Handle(CustomerInsertCommand command)
        {
            var response = new SimpleResponse <LongCommandResult>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var result = connection.PartialInsertAndReturnId <CustomerEntity>(new { command.FirstName, command.LastName });
                        response.ResponseCode = (int)result.Result;
                        response.RCode        = result.ToString();
                        response.Data         = new LongCommandResult {
                            ReturnValue = result.Result.ToLongNullable()
                        };
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
        public override SimpleResponse <LongCommandResult> Handle(StaffDeleteCommand command)
        {
            var response = new SimpleResponse <LongCommandResult>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var result = connection.DeleteAll <StaffEntity>(p => p.StaffId == command.Id);
                        response.ResponseCode = result;
                        response.RCode        = result.ToString();
                        response.Data         = new LongCommandResult {
                            ReturnValue = command.Id
                        };
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
        public override SimpleResponse <AddressResult> Handle(AddressReadByIdQuery query)
        {
            var response = new SimpleResponse <AddressResult>();

            try
            {
                if (query.Id == null)
                {
                    return(response);
                }

                if ((query.Id ?? 0) < 1)
                {
                    return(response);
                }

                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var actorEntList = connection.Select <AddressEntity>(p => p.AddressId == query.Id)?.ToList() ?? new List <AddressEntity>();
                        response.Data = new AddressResult
                        {
                            Address = (actorEntList.Select(p => new AddressViewModel
                            {
                                AddressId = p.AddressId,
                                Address = p.Address,
                                Address2 = p.Address2,
                                District = p.District,
                                CityId = p.CityId,
                                PostalCode = p.PostalCode,
                                Phone = p.Phone,
                                LastUpdate = p.LastUpdate
                            }).ToList() ?? new List <AddressViewModel>()).FirstOrDefault()
                        };
                        response.ResponseCode = response.Data != null ? 1 : 0;
                        response.RCode        = response.ResponseCode.ToString();
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
        public override SimpleResponse <CustomerResult> Handle(CustomerReadByIdQuery query)
        {
            var response = new SimpleResponse <CustomerResult>();

            try
            {
                if (query.Id == null)
                {
                    return(response);
                }

                if ((query.Id ?? 0) < 1)
                {
                    return(response);
                }

                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var CustomerEntList = connection.Select <CustomerEntity>(p => p.CustomerId == query.Id)?.ToList() ?? new List <CustomerEntity>();
                        response.Data = new CustomerResult
                        {
                            Customer = (CustomerEntList.Select(p => new CustomerViewModel
                            {
                                CustomerId = p.CustomerId,
                                FirstName = p.FirstName,
                                LastName = p.LastName,
                                LastUpdate = p.LastUpdate
                            }).ToList() ?? new List <CustomerViewModel>()).FirstOrDefault()
                        };
                        response.ResponseCode = response.Data != null ? 1 : 0;
                        response.RCode        = response.ResponseCode.ToString();
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #13
0
        public override SimpleResponse <LongCommandResult> Handle(FilmInsertCommand command)
        {
            var response = new SimpleResponse <LongCommandResult>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var result = connection.PartialInsertAndReturnId <FilmEntity>(new
                        {
                            command.Title,
                            command.Description,
                            command.ReleaseYear,
                            command.LanguageId,
                            command.OriginalLanguageId,
                            command.RentalDuration,
                            command.RentalRate,
                            command.Length,
                            command.ReplacementCost,
                            command.Rating,
                            command.SpecialFeatures,
                            command.Fulltext
                        });
                        response.ResponseCode = (int)result.Result;
                        response.RCode        = result.ToString();
                        response.Data         = new LongCommandResult {
                            ReturnValue = result.Result.ToLongNullable()
                        };
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #14
0
        public override SimpleResponse <AddressList> Handle(AddressReadAllQuery query)
        {
            var response = new SimpleResponse <AddressList>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var actorEntList = connection.GetAll <AddressEntity>();
                        // var result = connection.QueryList<Syp.Entity.ServiceDetailType>("select * from service_detail_type where is_deleted = false and lower(detail_type_name) like '%' || :name || '%'", new { name = query.Name.ToLowerInvariant() });
                        response.Data = new AddressList
                        {
                            Addresses = actorEntList.Select(p => new AddressViewModel
                            {
                                AddressId  = p.AddressId,
                                Address    = p.Address,
                                Address2   = p.Address2,
                                District   = p.District,
                                CityId     = p.CityId,
                                PostalCode = p.PostalCode,
                                Phone      = p.Phone,
                                LastUpdate = p.LastUpdate
                            }).ToList() ?? new List <AddressViewModel>()
                        };
                        response.ResponseCode = response.Data?.Addresses?.Count ?? 0;
                        response.RCode        = response.ResponseCode.ToString();
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
        public override SimpleResponse <LongCommandResult> Handle(StaffUpdateCommand command)
        {
            var response = new SimpleResponse <LongCommandResult>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var result = connection.PartialUpdate <StaffEntity>(new
                        {
                            command.FirstName,
                            command.LastName,
                            command.AddressId,
                            command.Email,
                            command.StoreId,
                            command.Active,
                            command.Username,
                            command.Password,
                            command.LastUpdate,
                            command.Picture
                        }, p => p.StaffId == command.StaffId);
                        response.ResponseCode = result;
                        response.RCode        = result.ToString();
                        response.Data         = new LongCommandResult {
                            ReturnValue = command.StaffId
                        };
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #16
0
        public override SimpleResponse <StoreResult> Handle(StoreReadByIdQuery query)
        {
            var response = new SimpleResponse <StoreResult>();

            try
            {
                if (query.Id == null)
                {
                    return(response);
                }

                if ((query.Id ?? 0) < 1)
                {
                    return(response);
                }

                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var StoreEntList = connection.Select <StoreEntity>(p => p.StoreId == query.Id)?.ToList() ?? new List <StoreEntity>();
                        response.Data = new StoreResult
                        {
                            Store = (StoreEntList.Select(p => Map <StoreEntity, StoreViewModel>(p)).ToList() ?? new List <StoreViewModel>()).FirstOrDefault()
                        };
                        response.ResponseCode = response.Data != null ? 1 : 0;
                        response.RCode        = response.ResponseCode.ToString();
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #17
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);
        }
        public override SimpleResponse <CustomerList> Handle(CustomerReadAllQuery query)
        {
            var response = new SimpleResponse <CustomerList>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var CustomerEntList = connection.GetAll <CustomerEntity>();
                        // var result = connection.QueryList<Syp.Entity.ServiceDetailType>("select * from service_detail_type where is_deleted = false and lower(detail_type_name) like '%' || :name || '%'", new { name = query.Name.ToLowerInvariant() });
                        response.Data = new CustomerList
                        {
                            Customers = CustomerEntList.Select(p => new CustomerViewModel
                            {
                                CustomerId = p.CustomerId,
                                FirstName  = p.FirstName,
                                LastName   = p.LastName,
                                LastUpdate = p.LastUpdate
                            }).ToList() ?? new List <CustomerViewModel>()
                        };
                        response.ResponseCode = response.Data?.Customers?.Count ?? 0;
                        response.RCode        = response.ResponseCode.ToString();
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
        public override SimpleResponse <LongCommandResult> Handle(AddressInsertCommand command)
        {
            var response = new SimpleResponse <LongCommandResult>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var result = connection.PartialInsertAndReturnId <AddressEntity>(new
                        {
                            command.Address,
                            command.Address2,
                            command.CityId,
                            command.District,
                            command.PostalCode,
                            command.Phone
                        });
                        response.ResponseCode = (int)result.Result;
                        response.RCode        = result.ToString();
                        response.Data         = new LongCommandResult {
                            ReturnValue = result.Result.ToLongNullable()
                        };
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }
Example #20
0
        public override SimpleResponse <LongCommandResult> Handle(PaymentUpdateCommand command)
        {
            var response = new SimpleResponse <LongCommandResult>();

            try
            {
                using (var connection = GetDbConnection())
                {
                    try
                    {
                        connection.OpenIfNot();
                        var result = connection.PartialUpdate <PaymentEntity>(new
                        {
                            command.CustomerId,
                            command.StaffId,
                            command.RentalId,
                            command.Amount,
                            command.PaymentDate,
                            command.LastUpdate
                        }, p => p.PaymentId == command.PaymentId);
                        response.ResponseCode = result;
                        response.RCode        = result.ToString();
                        response.Data         = new LongCommandResult {
                            ReturnValue = command.PaymentId
                        };
                    }
                    finally
                    {
                        connection.CloseIfNot();
                    }
                }
            }
            catch (Exception ex)
            {
                response.ResponseCode = -500;
                DayLogger.Error(ex);
            }

            return(response);
        }