Example #1
0
        internal static TaxiServiceModel CreateTaxiService(TaxiServiceEntity service)
        {
            try
            {
                using (SriLankaToursEntities context = new SriLankaToursEntities())
                {
                    bool isServiceExists = context.TaxiServiceEntities.Any(x => (x.FromId == service.FromId) && (x.ToId == service.ToId) && (x.VehicleId == service.VehicleId));

                    if (isServiceExists)
                        throw new TaxiServiceExistsException("Taxi service already exists");

                    context.TaxiServiceEntities.Add(service);
                    context.SaveChanges();

                    vTaxiService view = context.vTaxiServices.First(x => x.ServiceId == service.ServiceId);

                    Mapper.CreateMap<vTaxiService, TaxiServiceModel>();
                    return Mapper.Map<TaxiServiceModel>(view);

                }

            }
            catch (Exception)
            {

                throw;
            }
        }
Example #2
0
        internal static TaxiServiceModel UpdateTaxiService(TaxiServiceEntity service)
        {
            try
            {
                using (SriLankaToursEntities context = new SriLankaToursEntities())
                {

                    bool isServiceExists = context.TaxiServiceEntities.Any(x => (x.FromId == service.FromId) && (x.ToId == service.ToId) &&
                        (x.VehicleId == service.VehicleId) && (x.ServiceId != service.ServiceId));

                    if (isServiceExists)
                        throw new TaxiServiceExistsException("Taxi service already exists");

                    TaxiServiceEntity entity = context.TaxiServiceEntities.Find(service.ServiceId);

                    entity.Price = service.Price;
                    entity.Visible = service.Visible;
                    entity.FromId = service.FromId;
                    entity.ToId = service.ToId;
                    entity.UpdatedBy = service.UpdatedBy;
                    entity.UpdatedOn = service.UpdatedOn;

                    context.SaveChanges();

                    return GetTaxiService(entity.ServiceId);

                }

            }
            catch (Exception)
            {

                throw;
            }
        }