Ejemplo n.º 1
0
        public async Task <ContentResult> CreateOrUpdate(EventDto eventDto)
        {
            ReturnMessage rm = new ReturnMessage(1, "Success");

            try
            {
                var events = await Task.Run(() => _unitOfWork.Events.GetAsync(filter: e => e.Id == eventDto.Id));

                var eventToAdd = _mapper.Map <Event>(eventDto);

                if (events.Count() == 0)
                {
                    eventDto.Id = 0;
                    _unitOfWork.Events.Add(eventToAdd);
                }
                else
                {
                    _unitOfWork.Events.Update(eventToAdd);
                }

                var status = _unitOfWork.Complete();
                _logger.LogInformation("Log:Add Event for ID: {Id}", eventToAdd.Id);
                return(this.Content(rm.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                rm.msg     = ex.Message.ToString();
                rm.msgCode = 0;
                return(this.Content(rm.returnMessage(null)));
            }
        }
Ejemplo n.º 2
0
        public ContentResult MakePayment(PaymentDto payDto)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Payment Made ");

            try
            {
                var invoice = _unitOfWork.Invoices.Find(x => x.Id == payDto.InvoiceId).SingleOrDefault();

                invoice.status = true;
                var paymenttotadd = _mapper.Map <Payment>(payDto);
                paymenttotadd.ReceiptNumber = "REC-" + payDto.InvoiceId.ToString();
                _unitOfWork.Payments.Add(paymenttotadd);
                _unitOfWork.Invoices.Update(invoice);
                var status = _unitOfWork.Complete();
                _logger.LogInformation("Log:Add Payment for ID: {Id}", paymenttotadd.Id);
                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
Ejemplo n.º 3
0
        public async Task <ContentResult> CreateOrUpdateCustomer(CustomerDto customerDto)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Customer Saved Succesfully");

            try
            {
                var customer = await Task.Run(() => _unitOfWork.Customers.GetAsync(filter: w => w.Id == customerDto.Id));

                var customerToAdd = _mapper.Map <Customer>(customerDto);
                if (customer.Count() == 0)
                {
                    _unitOfWork.Customers.Add(customerToAdd);
                }
                else
                {
                    _unitOfWork.Customers.Update(customerToAdd);
                }
                var status = _unitOfWork.Complete();
                _logger.LogInformation("Log:Add Customer for ID: {Id}", customerToAdd.Id);
                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
Ejemplo n.º 4
0
        public async Task <ContentResult> DeleteBooking(GetBookingInput input)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Booking Cancelled");

            try
            {
                var booking = await Task.Run(() => _unitOfWork.Bookings.GetAsync(filter: w => w.Id == input.Id));

                if (booking.Count() == 0)
                {
                    returnmessage.msgCode = -2;
                    returnmessage.msg     = "Booking Not Found";
                }
                else
                {
                    _unitOfWork.Bookings.Remove(booking.First());
                }
                _unitOfWork.Complete();
                _logger.LogInformation("Log:Delete Booking for ID: {Id}", input.Id);

                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
Ejemplo n.º 5
0
        public async Task <ContentResult> DeleteCustomer(GetCustomerInput input)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Customer Deleted Succesfully");

            try
            {
                var customer = await Task.Run(() => _unitOfWork.Customers.GetAsync(filter: w => w.Id == input.CustomerID));

                if (customer.Count() == 0)
                {
                    returnmessage.msgCode = -2;
                    returnmessage.msg     = "Customer Not Found";
                }
                else
                {
                    _unitOfWork.Customers.Remove(customer.First());
                }
                _unitOfWork.Complete();
                _logger.LogInformation("Log:Delete Customer for ID: {Id}", input.CustomerID);

                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
        public async Task <ContentResult> Delete(GetProductInput input)
        {
            ReturnMessage rm = new ReturnMessage(1, "Success");

            try
            {
                var products = await Task.Run(() => _unitOfWork.Products.GetAsync(filter: e => e.Id == input.Id));

                if (products.Count() == 0)
                {
                    rm.msgCode = -1;
                    rm.msg     = "Not Found";
                }
                else
                {
                    _unitOfWork.Products.Remove(products.First());
                    _unitOfWork.Complete();
                }

                _logger.LogInformation("Log:Delete Product for ID: {Id}", input.Id);
                return(this.Content(rm.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                rm.msg     = ex.Message.ToString();
                rm.msgCode = 0;
                return(this.Content(rm.returnMessage(null)));
            }
        }
Ejemplo n.º 7
0
        public async Task <ContentResult> createOrUpdateCarService(ServiceHistoryDto carserviceDto)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Car Service History Saved Succesfully");

            try
            {
                var service = await Task.Run(() => _unitOfWork.ServiceHistory.GetAsync(filter: w => w.Id == carserviceDto.Id));

                var serviceToAdd = _mapper.Map <ServiceHistory>(carserviceDto);


                if (service.Count() == 0)
                {
                    _unitOfWork.ServiceHistory.Add(serviceToAdd);
                }
                else
                {
                    _unitOfWork.ServiceHistory.Update(serviceToAdd);
                }
                var status = _unitOfWork.Complete();
                _logger.LogInformation("Log:Add Car Service for ID: {Id}", serviceToAdd.Id);
                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
Ejemplo n.º 8
0
        public async Task <ContentResult> DeleteCarServiceHistory(GetServiceInput input)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Car Service History Deleted Succesfully");

            try
            {
                var service = await Task.Run(() => _unitOfWork.ServiceHistory.GetAsync(filter: w => w.Id == input.Id));

                if (service.Count() == 0)
                {
                    returnmessage.msgCode = -2;
                    returnmessage.msg     = "Service History Not Found";
                }
                else
                {
                    _unitOfWork.ServiceHistory.Remove(service.First());
                }
                _unitOfWork.Complete();
                _logger.LogInformation("Log:Delete Car Service for ID: {Id}", input.Id);

                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
Ejemplo n.º 9
0
        public async Task <ContentResult> CreateOrUpdateBranch(BranchDto branchDto)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Branch Saved Succesfully");

            try
            {
                var branch = await Task.Run(() => _unitOfWork.Branchs.GetAsync(filter: w => w.Id == branchDto.Id));

                var branchToAdd = _mapper.Map <Branch>(branchDto);
                if (branch.Count() == 0)
                {
                    branchToAdd.Id = 0;
                    _unitOfWork.Branchs.Add(branchToAdd);
                }
                else
                {
                    _unitOfWork.Branchs.Update(branchToAdd);
                }
                var status = _unitOfWork.Complete();
                _logger.LogInformation("Log:Add Branch for ID: {Id}", branchToAdd.Id);
                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
Ejemplo n.º 10
0
        public async Task <Object> OnRegisterAsync(RegisterUserDto Input)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Staff Created Successfully ");

            try
            {
                var existinguser = await _userManager.FindByNameAsync(Input.Email);

                if (existinguser != null)
                {
                    returnmessage.msg     = "Staff Already Exist";
                    returnmessage.msgCode = -3;
                }
                else
                {
                    var user = new ApplicationUser {
                        UserName = Input.Username, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName
                    };
                    var result = await _userManager.CreateAsync(user, Input.Password);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("Staff created a new account with password.");

                        var roleCheck = await _roleManager.RoleExistsAsync(Input.UserRole);

                        if (!roleCheck)
                        {
                            returnmessage.msg     = "Role Doesnot Exist";
                            returnmessage.msgCode = -3;
                        }

                        await _userManager.AddToRoleAsync(user, Input.UserRole);

                        _unitOfWork.BranchStaff.Add(new BranchStaff
                        {
                            StaffId  = user.Id,
                            BranchId = Input.BranchId
                        });
                        _unitOfWork.Complete();
                    }
                    else
                    {
                        returnmessage.msg     = result.Errors.FirstOrDefault().Description;
                        returnmessage.msgCode = -3;
                    }
                }

                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
Ejemplo n.º 11
0
        public async Task <ContentResult> Post(RegistrationDto registrationDto)
        {
            try
            {
                ReturnMessage          returnmessage = new ReturnMessage(-4, "Login Failed");
                List <RegistrationDto> userlist      = new List <RegistrationDto>();
                var userToVerify = await _userManager.FindByNameAsync(registrationDto.UserName);

                if (userToVerify != null)
                {
                    // check the credentials

                    if (await _userManager.CheckPasswordAsync(userToVerify, registrationDto.Password))
                    {
                        returnmessage.msgCode = 1;
                        returnmessage.msg     = "Login Succeful";
                        var userstoreturn = _mapper.Map <RegistrationDto>(userToVerify);
                        userstoreturn.CurrentToken = GetRandomToken(userstoreturn.UserName);
                        userlist.Add(userstoreturn);
                    }
                }
                return(this.Content(returnmessage.returnMessage(new PagedResultDto <RegistrationDto>
                                                                    (userlist.AsQueryable(), 1, 1)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 12
0
        public async Task <ContentResult> GetCarDetails(GetCarInput input)
        {
            try
            {
                ReturnMessage rm   = new ReturnMessage(1, "Success");
                var           cars = await Task.Run(() => _unitOfWork.Cars.GetAsync(filter: w => input.Id != 0 ? (w.Id == input.Id) : true, includeProperties: "CarClassification"));

                var carsToReturn = _mapper.Map <IEnumerable <CarDto> >(cars);
                foreach (var item in carsToReturn)
                {
                    item.PassengerCount = item.CarClassification.PassengerCount;
                    item.CostPerHour    = item.CarClassification.CostPerHour;
                    item.CostPerDay     = item.CarClassification.CostPerDay;
                    item.LateFeePerHour = item.CarClassification.LateFeePerHour;
                }
                return(this.Content(rm.returnMessage(new PagedResultDto <CarDto>
                                                         (carsToReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 13
0
        public async Task <ContentResult> CreateOrUpdateCar(CarDto carDto)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Car Saved Succesfully");

            try
            {
                carDto.CarClassification = new CarClassificationDto()
                {
                    PassengerCount = carDto.PassengerCount,
                    CostPerDay     = carDto.CostPerDay,
                    CostPerHour    = carDto.CostPerHour,
                    LateFeePerHour = carDto.LateFeePerHour
                };
                var car = await Task.Run(() => _unitOfWork.Cars.GetAsync(filter: w => carDto.Id != 0 ? (w.Id == carDto.Id) : true, includeProperties: "CarClassification"));

                int carclassificationid    = car.First().CarClassification.Id;
                var carToAdd               = _mapper.Map <Car>(carDto);
                var carClassificationToAdd = _mapper.Map <CarClassification>(carDto.CarClassification);

                if (car.Count() == 0)
                {
                    carToAdd.Id = 0;
                    carToAdd.CarClassification = carClassificationToAdd;
                    _unitOfWork.CarClassification.Add(carClassificationToAdd);
                    _unitOfWork.Cars.Add(carToAdd);
                }
                else
                {
                    carToAdd.CarClassificationId = carclassificationid;
                    carClassificationToAdd.Id    = carclassificationid;
                    _unitOfWork.CarClassification.Update(carClassificationToAdd);
                    _unitOfWork.Cars.Update(carToAdd);
                }
                var status = _unitOfWork.Complete();
                _logger.LogInformation("Log:Add Car for ID: {Id}", carToAdd.Id);
                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
Ejemplo n.º 14
0
        public async Task <ContentResult> DeleteUser(GetUserInput input)
        {
            ReturnMessage returnmessage = new ReturnMessage(1, "Staff Deleted Succesfully");

            try
            {
                if (string.IsNullOrEmpty(input.Email))
                {
                    returnmessage.msg     = "Staff Not Found";
                    returnmessage.msgCode = -2;
                    return(this.Content(returnmessage.returnMessage(null)));
                }

                var user = await _userManager.FindByEmailAsync(input.Email);

                if (user == null)
                {
                    returnmessage.msg     = "Staff Not Found";
                    returnmessage.msgCode = -2;
                    return(this.Content(returnmessage.returnMessage(null)));
                }

                // If User is a Registered Branch Staff Then Remove it.
                var staffOfBranch = await _unitOfWork.BranchStaff.GetAsync(filter : w => w.StaffId == user.Id);

                if (staffOfBranch.Count() != 0)
                {
                    _unitOfWork.BranchStaff.Remove(staffOfBranch.First());
                }

                await _userManager.DeleteAsync(user);

                _logger.LogInformation("Log:Delete Staff for Email: {Email}", user.Email);

                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }
        public async Task <ContentResult> CreateOrder(NewOrderDto order)
        {
            ReturnMessage rm = new ReturnMessage(1, "Success");

            try
            {
                var customer = _mapper.Map <Customer>(order.Customer);
                var address  = _mapper.Map <Address>(order.Address);
                var payment  = _mapper.Map <Payment>(order.Payment);


                var customerAdded = _unitOfWork.Customers._Add(customer);
                var addressAdded  = _unitOfWork.Address._Add(address);
                var paymentAdded  = _unitOfWork.Payments._Add(payment);

                var orderAdded = _unitOfWork.Orders._Add(new Order()
                {
                    Message      = order.Message,
                    Status       = "Pending",
                    Customer     = customerAdded,
                    OrderAddress = addressAdded,
                    Payment      = paymentAdded,
                    CreatedAt    = DateTime.Now,
                    UpdatedAt    = DateTime.Now,
                    OrderAt      = order.OrderTime
                });

                foreach (var item in order.Product)
                {
                    _unitOfWork.OrderDetails.Add(new OrderDetail()
                    {
                        Quantity  = item.Quantity,
                        Message   = item.Message,
                        Order     = orderAdded,
                        ProductId = item.ProductId,
                        SizeId    = item.SizeId
                    });
                }

                _unitOfWork.Complete();

                return(this.Content(rm.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    // 0 is Exception
                    msgCode = 0,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 16
0
        public async Task <ContentResult> GetInvoiceItem(GetInvoiceInput input)
        {
            try
            {
                List <ExtraDto> extralist = new List <ExtraDto>();
                ReturnMessage   rm        = new ReturnMessage(1, "Success");
                var             invoices  = await Task.Run(() => _unitOfWork.Invoices.GetAsync(filter: w => input.Id != 0 ? (w.Id == input.Id) : true, includeProperties: "Customer,Booking"));

                var invoicesToReturn = _mapper.Map <IEnumerable <InvoiceDto> >(invoices);
                //  var extra = _unitOfWork.BookingExtras.Find(x => x.BookingId == invoices.First().Booking.Id);
                var extra = await Task.Run(() => _unitOfWork.BookingExtras.GetAsync(filter: w => w.BookingId == invoices.First().BookingId, includeProperties: "Extra"));

                var cars = await Task.Run(() => _unitOfWork.Cars.GetAsync(filter: w => w.Id == invoices.First().Booking.CarId, includeProperties: "CarClassification"));

                var        car        = _mapper.Map <IEnumerable <CarDto> >(cars).First();
                var        payment    = _unitOfWork.Payments.Find(x => x.InvoiceId == input.Id).SingleOrDefault();
                PaymentDto paymentDto = _mapper.Map <PaymentDto>(payment);
                if (paymentDto != null)
                {
                    paymentDto.PaymentType = ((Utility.PaymentType)Convert.ToInt32(paymentDto.PaymentType)).ToString();
                }
                foreach (var item in extra)
                {
                    var extraDto = _mapper.Map <ExtraDto>(item.Extra);
                    extraDto.Count = item.Count ?? 0;
                    extralist.Add(extraDto);
                }
                InvoiceDetailDto invoiceDetail = new InvoiceDetailDto()
                {
                    Invoice          = invoicesToReturn.First(),
                    InvoiceId        = invoicesToReturn.First().Id,
                    Booking          = invoicesToReturn.First().Booking,
                    BookingExtraList = extralist,
                    Car     = car,
                    Payment = paymentDto
                };

                List <InvoiceDetailDto> invoicedetailList = new List <InvoiceDetailDto>();
                invoicedetailList.Add(invoiceDetail);

                return(this.Content(rm.returnMessage(new PagedResultDto <InvoiceDetailDto>
                                                         (invoicedetailList.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 17
0
        public async Task <ContentResult> GetAll(GetUserInput input)
        {
            try
            {
                ReturnMessage rm           = new ReturnMessage(1, "Success");
                var           current_user = HttpContext.Session.GetObjectFromJson <RegisterUserDto>("current_user");
                IEnumerable <ApplicationUser> userInDb;
                if (current_user.BranchId != 3)
                {
                    var users = await Task.Run(() => _unitOfWork.BranchStaff.GetAsync(filter: w => w.BranchId == current_user.BranchId, includeProperties: "Staff"));

                    List <string> usersinbranch = new List <string>();
                    foreach (var item in users)
                    {
                        usersinbranch.Add(item.Staff.Id);
                    }

                    userInDb = _userManager.Users.ToList().Where(x => usersinbranch.Contains(x.Id));
                }
                else
                {
                    if (input.Id != null)
                    {
                        userInDb = _userManager.Users.ToList().Where(x => x.Id == input.Id);
                    }
                    else
                    {
                        userInDb = _userManager.Users.ToList();
                    }
                }


                var userToReturn = _mapper.Map <IEnumerable <RegisterUserDto> >(userInDb);
                foreach (var item in userToReturn)
                {
                    var branch = await Task.Run(() => _unitOfWork.BranchStaff.GetAsync(filter: w => w.StaffId == item.Id));

                    item.BranchId = branch.First().BranchId;
                }
                return(this.Content(rm.returnMessage(new PagedResultDto <RegisterUserDto>
                                                         (userToReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 18
0
        public ContentResult GetRoles()
        {
            //TODO:
            // have to do pagination thing, otherwise angular component wasn't working.
            ReturnMessage rm                = new ReturnMessage(1, "Success");
            var           identityRoles     = _roleManager.Roles.ToList();
            var           userRolesToReturn =
                _mapper.Map <IEnumerable <IdentityRoleDto> >(identityRoles);

            return(this.Content(rm.returnMessage(new PagedResultDto <IdentityRoleDto>
                                                     (userRolesToReturn.AsQueryable(), 1, 10)),
                                "application/json"));
        }
Ejemplo n.º 19
0
        public async Task <ContentResult> GetBooking(GetBookingInput input)
        {
            try
            {
                IEnumerable <Booking> bookings;
                ReturnMessage         rm = new ReturnMessage(1, "Success");
                var current_user         = HttpContext.Session.GetObjectFromJson <RegisterUserDto>("current_user");
                if (current_user.BranchId != 3 || current_user.UserRole == "Staff")
                {
                    var users = await Task.Run(() => _unitOfWork.BranchStaff.GetAsync(filter: w => w.BranchId == current_user.BranchId, includeProperties: "Staff"));

                    List <string> usersinbranch = new List <string>();
                    foreach (var item in users)
                    {
                        usersinbranch.Add(item.Staff.UserName);
                    }
                    bookings = await Task.Run(() => _unitOfWork.Bookings.GetAsync(filter: w => ((input.Id != 0 ? (w.Id == input.Id) : true) && ((w.ToBranchId == current_user.BranchId) || (w.FromBranchId == current_user.BranchId) || (usersinbranch.Contains(w.CreatedBy)))), includeProperties: "FromBranch,ToBranch,Car,Customer"));
                }
                else
                {
                    bookings = await Task.Run(() => _unitOfWork.Bookings.GetAsync(filter: w => input.Id != 0 ? (w.Id == input.Id) : true, includeProperties: "FromBranch,ToBranch,Car,Customer"));
                }

                var bookingdToReturn = _mapper.Map <IEnumerable <BookingDto> >(bookings);
                foreach (var item in bookingdToReturn)
                {
                    item.bookingextras = GetBookingExtras(new GetBookingExtraInput()
                    {
                        BookingId = item.Id
                    });
                    var invoice = _unitOfWork.Invoices.Find(x => x.BookingId == item.Id).First();
                    item.Invoice = _mapper.Map <InvoiceDto>(invoice);
                }

                return(this.Content(rm.returnMessage(new PagedResultDto <BookingDto>
                                                         (bookingdToReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 20
0
        public async Task <ContentResult> GetCar(GetCarInput input)
        {
            var est = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");

            input.AvailableDateCheck = TimeZoneInfo.ConvertTime(input.AvailableDateCheck, est);

            try
            {
                ReturnMessage rm   = new ReturnMessage(1, "Success");
                var           cars = await Task.Run(() => _unitOfWork.Cars.GetAsync(filter: w => (input.Id != 0 ? (w.Id == input.Id) : true) &&
                                                                                    (input.RegistrationNumber != null? (w.RegistrationNumber.Contains(input.RegistrationNumber)) : true) &&
                                                                                    (input.Model != null? (w.Model.Contains(input.Model)) : true) &&
                                                                                    (input.Year != 0? (w.Year.ToString().Contains(input.Year.ToString())) : true),

                                                                                    includeProperties: "CarClassification"));

                var carsToReturn = _mapper.Map <IEnumerable <CarDto> >(cars);
                foreach (var item in carsToReturn)
                {
                    item.CarAvailability = GetavailableTime(new GetCarInput()
                    {
                        Id = item.Id, AvailableDateCheck = input.AvailableDateCheck
                    });
                    var location = await Task.Run(() => _unitOfWork.Locations.GetAsync(filter: w => w.CarId == item.Id && w.isAtLocation == true, includeProperties: "Branch"));

                    if (location.Count() != 0)
                    {
                        item.CurrentLocation = location.First().Branch.BranchName;
                    }
                }
                return(this.Content(rm.returnMessage(new PagedResultDto <CarDto>
                                                         (carsToReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 21
0
        public async Task <Object> OnLoginAsync(LoginUserDto Input)
        {
            try
            {
                ReturnMessage          rm = new ReturnMessage(1, "Login Succesful");
                List <RegisterUserDto> registeruserlist = new List <RegisterUserDto>();
                var user = await _userManager.FindByNameOrEmailAsync(Input.Username);

                if (user != null && await _userManager.CheckPasswordAsync(user, Input.Password))
                {
                    var token        = GenerateSecurityToken(user);
                    var usertoreturn = _mapper.Map <RegisterUserDto>(user);

                    var branch = await Task.Run(() => _unitOfWork.BranchStaff.GetAsync(filter: w => w.StaffId == user.Id, includeProperties: "Branch"));

                    usertoreturn.CurrentToken = token;
                    usertoreturn.BranchId     = branch.ToList().First().BranchId;
                    usertoreturn.BranchName   = branch.ToList().First().Branch.BranchName;
                    var role = await _userManager.GetRolesAsync(user);

                    usertoreturn.UserRole = role[0];
                    registeruserlist.Add(usertoreturn);
                    HttpContext.Session.SetObjectAsJson("current_user", usertoreturn);
                }
                else
                {
                    rm.msgCode = -1;
                    rm.msg     = "Login Failed";
                }
                return(this.Content(rm.returnMessage(new PagedResultDto <RegisterUserDto>
                                                         (registeruserlist.AsQueryable(), 0, 0)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 22
0
        public async Task <ContentResult> GetCustomer(GetCustomerInput input)
        {
            try
            {
                ReturnMessage rm        = new ReturnMessage(1, "Success");
                var           customers = await Task.Run(() => _unitOfWork.Customers.GetAsync(filter: w => input.CustomerID != 0? (w.Id == input.CustomerID):true));

                var customersToReturn = _mapper.Map <IEnumerable <CustomerDto> >(customers);
                return(this.Content(rm.returnMessage(new PagedResultDto <CustomerDto>
                                                         (customersToReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex) {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 23
0
        public async Task <ContentResult> GetCarServiceDetails(GetServiceInput input)
        {
            try
            {
                ReturnMessage rm       = new ReturnMessage(1, "Success");
                var           services = await Task.Run(() => _unitOfWork.ServiceHistory.GetAsync(filter: w => input.Id != 0 ? (w.Id == input.Id) : true));

                var servicestoReturn = _mapper.Map <IEnumerable <ServiceHistoryDto> >(services);
                return(this.Content(rm.returnMessage(new PagedResultDto <ServiceHistoryDto>
                                                         (servicestoReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 24
0
        public async Task <ContentResult> GetExtras(GetExtraInput input)
        {
            try
            {
                ReturnMessage           rm = new ReturnMessage(1, "Success");
                IList <BookingExtraDto> bookingextralist = null;
                if (input.BookingId > 0)
                {
                    bookingextralist = GetBookingExtras(new GetBookingExtraInput()
                    {
                        BookingId = input.BookingId
                    });
                }

                var extras = await Task.Run(() => _unitOfWork.Extras.GetAsync(filter: w => input.Id != 0 ? (w.Id == input.Id) : true));

                var extrasToReturn = _mapper.Map <IEnumerable <ExtraDto> >(extras);
                if (bookingextralist != null)
                {
                    var result = extrasToReturn.Join(bookingextralist, d => d.ExtraId, s => s.ExtraId, (d, s) =>
                    {
                        d.Count = s.Count;
                        return(d);
                    }).ToList();
                }

                return(this.Content(rm.returnMessage(new PagedResultDto <ExtraDto>
                                                         (extrasToReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
Ejemplo n.º 25
0
        public async Task <ContentResult> GetInvoice(GetInvoiceInput input)
        {
            IEnumerable <Invoice> invoices;

            try
            {
                ReturnMessage rm           = new ReturnMessage(1, "Success");
                var           current_user = HttpContext.Session.GetObjectFromJson <RegisterUserDto>("current_user");
                if (current_user.BranchId != 3 || current_user.UserRole == "Staff")
                {
                    var users = await Task.Run(() => _unitOfWork.BranchStaff.GetAsync(filter: w => w.BranchId == current_user.BranchId, includeProperties: "Staff"));

                    List <string> usersinbranch = new List <string>();
                    foreach (var item in users)
                    {
                        usersinbranch.Add(item.Staff.UserName);
                    }
                    invoices = await Task.Run(() => _unitOfWork.Invoices.GetAsync(filter: w => (input.Id != 0 ? (w.Id == input.Id) : true) && usersinbranch.Contains(w.CreatedBy), includeProperties: "Customer,Booking"));
                }
                else
                {
                    invoices = await Task.Run(() => _unitOfWork.Invoices.GetAsync(filter: w => input.Id != 0 ? (w.Id == input.Id) : true, includeProperties: "Customer,Booking"));
                }

                var invoicesToReturn = _mapper.Map <IEnumerable <InvoiceDto> >(invoices);
                return(this.Content(rm.returnMessage(new PagedResultDto <InvoiceDto>
                                                         (invoicesToReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    msgCode = -3,
                    msg = ex.Message
                }), "application/json"));
            }
        }
        public async Task <ContentResult> GetAll(GetProductInput input)
        {
            try
            {
                ReturnMessage rm       = new ReturnMessage(1, "Success");
                var           products = await Task.Run(() => _unitOfWork.Products.GetAsync(filter: e => input.Id != 0 ? (e.Id == input.Id) : true));

                var productsToReturn = _mapper.Map <IEnumerable <ProductDto> >(products);

                return(this.Content(rm.returnMessage(new PagedResultDto <ProductDto>
                                                         (productsToReturn.AsQueryable(), input.pagenumber, input.pagesize)),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                return(this.Content(JsonConvert.SerializeObject(new
                {
                    // 0 is Exception
                    msgCode = 0,
                    msg = ex.Message
                }), "application/json"));
            }
        }
        public async Task <ContentResult> CreateOrUpdate([FromForm] ProductSaveDto productDto)
        {
            ReturnMessage rm        = new ReturnMessage(1, "Success");
            string        uploadUrl = null;

            try
            {
                var products = await Task.Run(() => _unitOfWork.Products.GetAsync(filter: e => e.Id == productDto.Id));

                var product = products.Where(x => x.Id.Equals(productDto.Id) && x.isActive).FirstOrDefault();

                //var productToAdd = _mapper.Map<Product>(productDto);
                if (productDto.Picture != null)
                {
                    var uploadResult = await _photoService.UploadAsync(productDto.Picture, Quality.Low);

                    if (uploadResult != null)
                    {
                        uploadUrl = uploadResult.Url;
                    }
                }

                if (products.Count() == 0)
                {
                    var productToAdd = new Product
                    {
                        Name        = productDto.Name,
                        Description = productDto.Description,
                        Price       = productDto.Price,
                        Image       = uploadUrl,
                        isActive    = true
                    };
                    _unitOfWork.Products.Add(productToAdd);
                }
                else
                {
                    product.Name        = productDto.Name;
                    product.Description = productDto.Description;
                    product.Price       = productDto.Price;
                    product.isActive    = true;
                    if (productDto.IsPictureChanged == 1)
                    {
                        product.Image = "";
                    }
                    else if (uploadUrl != null)
                    {
                        product.Image = uploadUrl;
                    }
                    _unitOfWork.Products.Update(product);
                }

                _unitOfWork.Complete();
                _logger.LogInformation("Log:Add Product for ID: {Id}", product.Id);
                return(this.Content(rm.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                rm.msg     = ex.Message.ToString();
                rm.msgCode = 0;
                return(this.Content(rm.returnMessage(null)));
            }
        }
Ejemplo n.º 28
0
        public async Task <ContentResult> CreateOrUpdateBooking(BookingDto bookingDto)
        {
            var           current_user       = HttpContext.Session.GetObjectFromJson <RegisterUserDto>("current_user");
            float         totalinvoiceamount = 0;
            Booking       bookingToAdd       = null;
            Invoice       invoicetoadd       = null;
            Customer      customer           = null;
            ReturnMessage returnmessage      = new ReturnMessage(1, "Booking Added ");

            try
            {
                int totaldays = (int)(Convert.ToDateTime(bookingDto.ReturnDate) - Convert.ToDateTime(bookingDto.FromDate)).TotalDays;
                var booking   = await Task.Run(() => _unitOfWork.Bookings.GetAsync(filter: w => w.Id == bookingDto.Id, includeProperties: (bookingDto.IsNewCustomer? "Customer":"")));

                bookingToAdd = _mapper.Map <Booking>(bookingDto);
                var est = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time");
                bookingToAdd.FromDate   = TimeZoneInfo.ConvertTime(bookingToAdd.FromDate, est);
                bookingToAdd.ReturnDate = TimeZoneInfo.ConvertTime(bookingToAdd.ReturnDate, est);
                var cars = await Task.Run(() => _unitOfWork.Cars.GetAsync(filter: w => w.Id == bookingDto.CarId, includeProperties: "CarClassification"));

                totalinvoiceamount     = totalinvoiceamount + ((cars.First().CarClassification.CostPerDay *totaldays));
                bookingToAdd.CreatedOn = DateTime.Now;
                bookingToAdd.CreatedBy = current_user.Username;
                if (booking.Count() == 0)
                {
                    if (!bookingDto.IsNewCustomer && bookingDto.CustomerId != 0)
                    {
                        bookingToAdd.Customer = null;
                        customer = _unitOfWork.Customers.Find(x => x.Id == bookingDto.CustomerId).First();
                    }

                    _unitOfWork.Bookings.Add(bookingToAdd);
                }
                else
                {
                    if (bookingDto.IsNewCustomer)
                    {
                        bookingToAdd.Customer.Id = booking.First().Customer.Id;
                        _unitOfWork.Customers.Update(bookingToAdd.Customer);
                    }
                    if (bookingToAdd.isActive == false)
                    {
                        var locationfromBranch = _unitOfWork.Locations.Find(x => x.CarId == bookingToAdd.CarId && x.BranchId == bookingToAdd.FromBranchId).First();
                        locationfromBranch.isAtLocation = false;
                        var locationtoBranch = _unitOfWork.Locations.Find(x => x.CarId == bookingToAdd.CarId && x.BranchId == bookingToAdd.ToBranchId).First();
                        locationtoBranch.isAtLocation = true;
                        _unitOfWork.Locations.Update(locationfromBranch);
                        _unitOfWork.Locations.Update(locationtoBranch);
                    }
                    _unitOfWork.Bookings.Update(bookingToAdd);
                }
                foreach (var item in bookingDto.bookingextras)
                {
                    if (item.PriceType == 2)
                    {
                        item.Count = totaldays;
                    }
                    var itemtoadd = _mapper.Map <BookingExtra>(item);
                    itemtoadd.Booking = bookingToAdd;
                    var extra = _unitOfWork.BookingExtras.Find(x => x.BookingId == itemtoadd.Booking.Id && x.ExtraId == itemtoadd.ExtraId);
                    if (extra.Count() > 0)
                    {
                        itemtoadd.Id = extra.First().Id;
                        _unitOfWork.BookingExtras.Update(itemtoadd);
                    }
                    else
                    {
                        _unitOfWork.BookingExtras.Add(itemtoadd);
                    }
                    float itemprice = (itemtoadd.Count * item.Price) ?? 0;
                    totalinvoiceamount = totalinvoiceamount += itemprice;
                }

                if (bookingDto.Id == 0)
                {
                    long maxbookingid = _unitOfWork.Invoices.GetMaxBookingId();

                    InvoiceDto invoiceDto = new InvoiceDto()
                    {
                        InvoiceNumber = "INV-" + ((int)maxbookingid + 1).ToString(),
                        //  InvoiceNumber = "INV-" + bookingToAdd.Id.ToString(),
                        CustomerId  = bookingToAdd.CustomerId,
                        IssueDate   = DateTime.Now.ToString("yyyy/MM/dd HH:mm"),
                        DueDate     = bookingToAdd.FromDate.ToString("yyyy/MM/dd HH:mm"),
                        Description = "Invoice Created For the Booking by " + customer.FirstName,
                        Amount      = totalinvoiceamount,
                        CreatedBy   = current_user.Username,
                        CreatedOn   = DateTime.Now
                    };

                    invoicetoadd         = _mapper.Map <Invoice>(invoiceDto);
                    invoicetoadd.Booking = bookingToAdd;
                    _unitOfWork.Invoices.Add(invoicetoadd);
                }

                var status = _unitOfWork.Complete();
                _logger.LogInformation("Log:Add Booking for ID: {Id}", bookingToAdd.Id);
                return(this.Content(returnmessage.returnMessage(null),
                                    "application/json"));
            }
            catch (Exception ex)
            {
                returnmessage.msg     = ex.Message.ToString();
                returnmessage.msgCode = -3;
                return(this.Content(returnmessage.returnMessage(null)));
            }
        }