Exemplo n.º 1
0
        public NISIS_Ward CreateWard(NISIS_Ward NewEntry, string loginName)
        {
            var WardObj = (from p in dbContext.NISIS_Wards
                           where p.Description.Contains(NewEntry.Description)
                           select p).FirstOrDefault();

            if (WardObj == null)
            {
                var    newWard       = new NISIS_Ward();
                string NewWardNumber = (Convert.ToString(NewEntry.Description).Replace("Ward ", ""));
                string NewWardCode   = NewEntry.Description.Replace("Ward ", "00");
                newWard.Description           = NewEntry.Description;
                newWard.Local_Municipality_Id = (from a in dbContext.Local_Municipalities
                                                 where a.Local_Municipality_Id == NewEntry.Local_Municipality.Local_Municipality_Id
                                                 select a.Local_Municipality_Id).FirstOrDefault();
                newWard.Ward_Code    = NewWardCode;
                newWard.Ward_Number  = NewWardNumber;
                newWard.Date_Created = DateTime.Now;
                newWard.Created_By   = loginName;
                newWard.Is_Active    = true;
                newWard.Is_Deleted   = false;
                dbContext.NISIS_Wards.Add(newWard);
                dbContext.SaveChanges();
                return(newWard);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public NISIS_Ward EditWard(NISIS_Ward UpdatedObj, string loginName)
        {
            var WardObj = (from p in dbContext.NISIS_Wards
                           where p.NISIS_Ward_Id == UpdatedObj.NISIS_Ward_Id
                           select p).FirstOrDefault();
            string NewWardNumber = (Convert.ToString(UpdatedObj.Description).Replace("Ward ", ""));
            string NewWardCode   = UpdatedObj.Description.Replace("Ward ", "00");

            WardObj.Description           = UpdatedObj.Description;
            WardObj.Local_Municipality_Id = (from a in dbContext.Local_Municipalities
                                             where a.Local_Municipality_Id == UpdatedObj.Local_Municipality.Local_Municipality_Id
                                             select a.Local_Municipality_Id).FirstOrDefault();
            WardObj.Ward_Code          = NewWardCode;
            WardObj.Ward_Number        = NewWardNumber;
            WardObj.Date_Last_Modified = DateTime.Now;
            WardObj.Last_Modified_By   = loginName;
            dbContext.SaveChanges();
            return(WardObj);
        }