Esempio n. 1
0
        public bool hideLocationCompany(int companyCode, int userId, string nameLocation)
        {
            bool status = false;

            try
            {
                if (companyCode != 0)
                {
                    company_location location = db.company_location.FirstOrDefault(item => (item.company_id == companyCode && item.location_en == nameLocation));

                    if (location != null)
                    {
                        location.status_id = 1;
                    }

                    db.company_location.AddOrUpdate(location);
                    db.SaveChanges();
                    status = true;
                }
            }
            catch (System.Data.DataException ex)
            {
                logger.Error(ex.ToString());
                return(false);
            }
            return(status);
        }
Esempio n. 2
0
 public string deleteLocation(SettingsViewModel newSetting)
 {
     try
     {
         if (newSetting.companyId > 0 && newSetting.userId > 0 && newSetting.data != null)
         {
             int count = db.company_location.Where(item => item.company_id == newSetting.companyId && item.status_id == 2).Count();
             if (count <= 1)
             {
                 return("false");
             }
             int idSetting = Int32.Parse(newSetting.data);
             company_location oldLocation = db.company_location.Where(item => item.id == idSetting).FirstOrDefault();
             if (oldLocation != null)
             {
                 oldLocation.status_id      = 1;
                 oldLocation.last_update_dt = DateTime.Now;
                 db.SaveChanges();
             }
         }
         else
         {
             return("false");
         }
     }
     catch (Exception e)
     {
         return("false");
     }
     return("true");
 }
Esempio n. 3
0
        public string addLocationCompany(SettingsViewModel newSetting)
        {
            string id = null;

            try
            {
                var data = newSetting.data == null ? new string[0] : newSetting.data.Split('\n');
                if (newSetting.companyId > 0 && newSetting.userId > 0 && data.Length == 2)
                {
                    var name = data[0].ToLower();
                    int extendId;
                    if (!int.TryParse(data[1], out extendId))
                    {
                        extendId = 0;
                    }
                    company_location oldLocation = db.company_location.Where(item => item.location_en.Trim().ToLower() == name && item.company_id == newSetting.companyId).FirstOrDefault();
                    if (oldLocation != null)
                    {
                        oldLocation.status_id = 2;
                        oldLocation.location_cc_extended_id = extendId == 0 ? null : (int?)extendId;
                        db.SaveChanges();
                        id = oldLocation.id.ToString();
                    }
                    else
                    {
                        company_location location = new company_location
                        {
                            client_id               = newSetting.userId,
                            company_id              = newSetting.companyId,
                            status_id               = 2,
                            location_en             = data[0],
                            last_update_dt          = DateTime.Now,
                            user_id                 = 1,
                            location_cc_extended_id = extendId == 0 ? null : (int?)extendId,
                        };
                        location = db.company_location.Add(location);
                        db.SaveChanges();
                        id = location.id.ToString();
                    }
                }
                else
                {
                    return("false");
                }
            }
            catch (System.Data.DataException ex)
            {
                logger.Error(ex.ToString());
                return("false");
            }
            return(id);
        }
Esempio n. 4
0
 public static string Location(this company_location location)
 {
     return(location.T("location"));
 }