Ejemplo n.º 1
0
        private async Task <bool> SubmitMorale(string Morale, string fingerprint = "")
        {
            string       strUserIP = string.Empty;
            SapeMoraleDB DBCon     = new SapeMoraleDB();

            _moraleRecDeleted = false;
            string IPAddress = Request.UserHostAddress;

            //string compName = DetermineCompName(IPAddress);

            strUserIP = string.Concat(Request.UserHostAddress, " | ", fingerprint);

            try
            {
                sape_morale moraleRec = DBCon.sape_morale.Where(m => DbFunctions.TruncateTime(m.LASTUPDATEDDATE) == DateTime.Today.Date && m.IPADDRESS == strUserIP).FirstOrDefault();

                if (moraleRec == null)
                {
                    // new record
                    moraleRec                 = new sape_morale();
                    moraleRec.IPADDRESS       = strUserIP;
                    moraleRec.MORALE          = Morale;
                    moraleRec.LASTUPDATEDDATE = DateTime.Now;
                    DBCon.sape_morale.Add(moraleRec);
                }
                else if (moraleRec.MORALE == Morale)
                {
                    // delete
                    DBCon.sape_morale.Remove(moraleRec);
                    _moraleRecDeleted = true;
                }
                else
                {
                    // update
                    moraleRec.MORALE          = Morale;
                    moraleRec.LASTUPDATEDDATE = DateTime.Now;
                }

                int result = await DBCon.SaveChangesAsync();

                if (result == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }