public async Task <string> DeleteDestinationAsync(long id)
        {
            try
            {
                utblMstDestination curObj = await objDB.utblMstDestinations.FindAsync(id);

                objDB.utblMstDestinations.Remove(curObj);
                await objDB.SaveChangesAsync();

                return("Destination Details Removed");
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error
                {
                    switch (ex.Errors[0].Number)
                    {
                    case 547:     // Foreign Key violation
                        return("This record has dependencies on other records, so cannot be removed.");

                    default:
                        return("Error: " + ex.Message);
                    }
                }
                return("Error while operation. Error Message: " + ex.Message);
            }
            catch (Exception ex)
            {
                return("Error: " + ex.Message);
            }
        }
Exemplo n.º 2
0
        public int Save(utblMstDestination destination)
        {
            int result = 0;

            if (destination.DestinationID == 0)
            {
                try
                {
                    _db.utblMstDestinations.Add(destination);
                    _db.SaveChanges();
                    result = 1;
                }
                catch (Exception ex)
                {
                    result = 0;
                }
            }
            else
            {
                utblMstDestination dbEntry = _db.utblMstDestinations.Find(destination.DestinationID);
                if (dbEntry != null)
                {
                    dbEntry.DestinationName = destination.DestinationName;
                    dbEntry.CountryID       = destination.CountryID;
                    dbEntry.DestinationDesc = destination.DestinationDesc;
                }
                _db.SaveChanges();
                result = 1;
            }
            return(result);
        }
        public async Task <string> SaveDestination(utblMstDestination model)
        {
            if (ModelState.IsValid)
            {
                return(await objDal.SaveDestinationAsync(model));
            }
            string messages = string.Join("; ", ModelState.Values
                                          .SelectMany(x => x.Errors)
                                          .Select(x => x.ErrorMessage));

            return("Operation Error: " + messages);
        }
Exemplo n.º 4
0
        public int Delete(long id)
        {
            int result             = 0;
            utblMstDestination obj = _db.utblMstDestinations.Find(id);

            try
            {
                _db.utblMstDestinations.Remove(obj);
                _db.SaveChanges();
                result = 1;
                return(result);
            }
            catch (Exception ex)
            {
                return(result);
            }
        }
        public async Task <string> SaveDestinationAsync(utblMstDestination model)
        {
            try
            {
                var parDestID    = new SqlParameter("@DestinationID", model.DestinationID);
                var parCountryID = new SqlParameter("@CountryID", model.CountryID);
                var parStateID   = new SqlParameter("@StateID", model.StateID);
                var parDestName  = new SqlParameter("@DestinationName", model.DestinationName);
                var parDestDesc  = new SqlParameter("@DestinationDesc", model.DestinationDesc ?? "");
                var parDestImg   = new SqlParameter("@DestinationImagePath", model.DestinationImagePath ?? "");

                return(await objDB.Database.SqlQuery <string>("udspMstDestinationSave @DestinationID, @CountryID, @StateID, @DestinationName, @DestinationDesc,@DestinationImagePath",
                                                              parDestID, parCountryID, parStateID, parDestName, parDestDesc, parDestImg).FirstOrDefaultAsync());
            }
            catch (Exception ex)
            {
                return("Error: " + ex.Message);
            }
        }
Exemplo n.º 6
0
        public utblMstDestination GetDestinationByID(long id)
        {
            utblMstDestination obj = _db.utblMstDestinations.FirstOrDefault(p => p.DestinationID == id);

            return(obj);
        }