public IHttpActionResult DeleteColor(int Id)
 {
     DAL.Color color = new DAL.Color();
     color          = Entities.Colors.Where(s => s.Id == Id).FirstOrDefault();
     color.IsActive = false;
     Entities.SaveChanges();
     return(Ok(true));
 }
 public IHttpActionResult AddColor(ColorModel Color)
 {
     DAL.Color color = new DAL.Color();
     color.Code       = Color.Code;
     color.ColorLong  = Color.ColorLong;
     color.ColorShort = Color.ColorShort;
     color.IsActive   = true;
     Entities.Colors.Add(color);
     Entities.SaveChanges();
     return(Ok(true));
 }
 public IHttpActionResult updateColor(ColorModel Color)
 {
     DAL.Color color = new DAL.Color();
     color            = Entities.Colors.Where(s => s.Id == Color.Id).FirstOrDefault();
     color.Code       = Color.Code;
     color.ColorLong  = Color.ColorLong;
     color.ColorShort = Color.ColorShort;
     color.IsActive   = Color.IsActive;
     Entities.SaveChanges();
     return(Ok(true));
 }
Example #4
0
        public IHttpActionResult updateColor(ColorModel Color)
        {
            var    list     = new List <Color>();
            var    pageName = Request.RequestUri.LocalPath.getRouteName();
            Object obj      = null;
            var    UserId   = 0;

            if (Request.Headers.Contains("Email"))
            {
                var email = ((string[])(Request.Headers.GetValues("Email")))[0].ToString();
                UserId = Entities.Users.Where(x => x.IsActive == true && x.Email.Contains(email)).FirstOrDefault().Id;
            }
            string logTable = "";

            DAL.Color color = new DAL.Color();
            color            = Entities.Colors.Where(s => s.Id == Color.Id || s.Code == Color.Code).FirstOrDefault();
            color.Code       = Color.Code;
            color.ColorLong  = Color.ColorLong;
            color.ColorShort = Color.ColorShort;
            color.UpdatedOn  = System.DateTime.UtcNow;
            color.IsActive   = Color.IsActive;
            try
            {
                Entities.SaveChanges();
                list.Add(color);
                return(Ok(true));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                obj = ex;
            }

            finally
            {
                if (obj == null)
                {
                    logTable = "";
                    var change = list.ToDataTables().getChangedRecords();
                    var c      = change.Count() / 2;
                    for (var i = 0; i < c; i++)
                    {
                        logTable += change[i].Fieldname + " Old Value=[" + change[i].FieldValue + "] New Value=[" + change[i + c].FieldValue + "], ";
                    }
                    //logTable = Newtonsoft.Json.JsonConvert.SerializeObject(change);
                    var flag = color.CreateLog(pageName, logTable, UserId);
                }
            }
            return(Ok(true));
        }
Example #5
0
        public IHttpActionResult AddColor(ColorModel Color)
        {
            var    pageName = Request.RequestUri.LocalPath.getRouteName();
            Object obj      = null;
            var    UserId   = 0;

            if (Request.Headers.Contains("Email"))
            {
                var email = ((string[])(Request.Headers.GetValues("Email")))[0].ToString();
                UserId = Entities.Users.Where(x => x.IsActive == true && x.Email.Contains(email)).FirstOrDefault().Id;
            }
            DAL.Color color = new DAL.Color();
            color.Code       = Color.Code;
            color.CreatedOn  = System.DateTime.UtcNow;
            color.UpdatedOn  = System.DateTime.UtcNow;
            color.ColorLong  = Color.ColorLong;
            color.ColorShort = Color.ColorShort;
            color.IsActive   = true;
            Entities.Colors.Add(color);
            try
            {
                Entities.SaveChanges();
            }
            catch (Exception ex) { obj = ex; }
            finally
            {
                if (obj == null)
                {
                    var logTable = Newtonsoft.Json.JsonConvert.SerializeObject(color, new JsonSerializerSettings()
                    {
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                        Formatting = Formatting.Indented
                    });
                    var flag = color.CreateLog(pageName, logTable, UserId);
                }
            }
            return(Ok(true));
        }