public static bool insertUserType(tblUserType userType, bool isInsert)
        {
            bool status = false;

            if (userType != null)
            {
                SampleDatabaseDataContext dc = new SampleDatabaseDataContext();

                if (isInsert)
                {
                    //Case of Inserting a new UserType
                    dc.tblUserTypes.InsertOnSubmit(userType);
                }
                else
                {
                    //Case of Updating a new UserType
                    tblUserType dbUserType = dc.tblUserTypes.Where(x => x.UserTypeID == userType.UserTypeID).SingleOrDefault();
                    dbUserType.Name = userType.Name;
                }

                dc.SubmitChanges();
                status = true;
            }

            return(status);
        }
Exemplo n.º 2
0
            /// <summary>
            /// Insert UserType Information
            /// </summary>
            /// <param name="data">UserType Information</param>
            /// <returns>Number Affected Row</returns>
            public static Tuple <ErrorObject, string> UserType(tblUserType data)
            {
                erros = new ErrorObject();
                try
                {
                    using (HSCMEntities db = new HSCMEntities())
                    {
                        int propertyFind = db.tblUserType.Count();
                        if (propertyFind > 0)
                        {
                            data.id = db.tblUserType.Max(s => s.id);
                        }
                        else
                        {
                            data.id = 1;
                        }
                        db.tblUserType.Add(data);
                        result  = db.SaveChanges();
                        Message = "Affected Row: " + result.ToString();

                        return(new Tuple <ErrorObject, string>(erros.IfError(false), Message));
                    }
                }
                catch (Exception ex)
                {
                    erros.InfoError(ex);
                    return(new Tuple <ErrorObject, string>(erros, String.Empty));
                }
            }
Exemplo n.º 3
0
            /// <summary>
            /// Return Affected Row Or Error If Exist
            /// </summary>
            /// <param name="request">CellarArea Information</param>
            /// <returns>Affected Row Or Error If Exist</returns>
            public static GetUserTypeResponse UserType(GetUserTypeResponse request)
            {
                GetUserTypeResponse response = new GetUserTypeResponse();

                try
                {
                    tblUserType UserType = new tblUserType()
                    {
                        id         = request.UserType.id,
                        name       = request.UserType.name,
                        detail     = request.UserType.detail,
                        createDate = request.UserType.createDate,
                        upDateDate = DateTime.Now,
                        deleteDate = null,
                        state      = "Active"
                    };

                    var result = UserTypeData.Update.UserType(UserType);
                    if (result.Item1.Error)
                    {
                        response.Error.InfoError(result.Item1);
                    }
                    else
                    {
                        response.Message = result.Item2;
                    }
                }
                catch (Exception ex)
                {
                    response.Error.InfoError(ex);
                }

                return(response);
            }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            tblUserType utype = new tblUserType();

            utype.UserTypeId = 6;
            utype.UserType   = "kushan";
            UnitOfWork unitOfWork = new UnitOfWork();
            IRepository <tblUserType> repository = unitOfWork.GetRepository <tblUserType>();

            repository.Insert(utype);
            unitOfWork.SaveChanges();
        }
Exemplo n.º 5
0
 protected void userTypeList_SelectedIndexChanged(object sender, EventArgs e)
 {
     btn_save.Text     = "Update";
     tb_userType.Text  = "";
     hdn_fieldID.Value = userTypeList.DataKeys[this.userTypeList.SelectedRow.RowIndex].Values[0].ToString();
     if (!string.IsNullOrEmpty(hdn_fieldID.Value))
     {
         tblUserType dbobj = UserTypeManager.getUserTypeById(new Guid(hdn_fieldID.Value));
         if (dbobj != null)
         {
             tb_userType.Text = dbobj.Name;
         }
     }
 }
Exemplo n.º 6
0
        public void DeleteTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                Guid        userTypeGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");
                tblUserType userType     = dc.tblUserTypes.FirstOrDefault(u => u.Id == userTypeGuid);

                dc.tblUserTypes.Remove(userType);

                dc.SaveChanges();

                tblUserType deletedUserType = dc.tblUserTypes.FirstOrDefault(u => u.Id == userTypeGuid);

                Assert.IsNull(deletedUserType);
            }
        }
Exemplo n.º 7
0
 bool IUserType.Insert(UserTypeViewModel model)
  {
      using (var ent = new CustomerSupportEntities())
      {
          var newRow = new tblUserType();
          newRow.UserTypeName = model.UserTypeName;
          newRow.UserTypes.Add(newRow);
          int success = ent.SaveChanges();
          if (success > 0)
          {
              return true;
          }
          else
          {
              return false;
          }
      }
  }
Exemplo n.º 8
0
        public void UpdateTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Retrieve test userType based on ID and update it
                Guid userTypeGuid = Guid.Parse("11112222-3333-4444-5555-666677778888");

                tblUserType userType = dc.tblUserTypes.FirstOrDefault(u => u.Id == userTypeGuid);

                userType.Description = "UpdatedUserType";

                //Save changes and get it back out
                dc.SaveChanges();
                tblUserType updatedUserType = dc.tblUserTypes.FirstOrDefault(u => u.Description == "UpdatedUserType");
                //Make sure the Ids match
                Assert.AreEqual(userType.Id, updatedUserType.Id);
            }
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            heading.Text = "Add User Type";
            bindData();
            lblerrormsg.Text = "  ";

            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    try
                    {
                        hdn_fieldID.Value = Request.QueryString["id"];
                        if (!string.IsNullOrEmpty(hdn_fieldID.Value))
                        {
                            btn_save.Text = "Update";
                            heading.Text  = "Update User Type";
                            tblUserType dbobj = UserTypeManager.getUserTypeById(new Guid(hdn_fieldID.Value));
                            if (dbobj != null)
                            {
                                tb_userType.Text = dbobj.Name;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        lblerrormsg.Text = ex.Message;
                    }
                }

                if (!string.IsNullOrEmpty(Request.QueryString["stat"]))
                {
                    string message = Request.QueryString["stat"];
                    if (message == "updateSuccess")
                    {
                        lblerrormsg.Text = "User Type Updated Successfully";
                    }
                    else if (message == "updateFail")
                    {
                        lblerrormsg.Text = "Could Not Update User Type";
                    }
                }
            }
        }
        public static bool deleteUserType(tblUserType userType)
        {
            bool status = false;

            if (userType != null)
            {
                SampleDatabaseDataContext dc = new SampleDatabaseDataContext();
                tblUserType dbobj            = dc.tblUserTypes.Where(x => x.UserTypeID == userType.UserTypeID).SingleOrDefault();

                if (dbobj != null)
                {
                    dc.tblUserTypes.DeleteOnSubmit(dbobj);
                    dc.SubmitChanges();
                    status = true;
                }
            }

            return(status);
        }
Exemplo n.º 11
0
        protected void userTypeList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //Fetch the Id of the Current userType that is we want to delete
            try
            {
                hdn_fieldID.Value = userTypeList.DataKeys[e.RowIndex].Values[0].ToString();
            }
            catch (Exception ex)
            {
                lblerrormsg.Text = ex.Message;
            }

            /*
             * //Validate if such Category is being used by any od the users or not!
             * //Fetch all userTypes being selected
             * //Later to be changed to Guid
             * foreach (UserDetail user in UserManager.GetAllUsers()) {
             *  try
             *  {
             *      if (hdn_fieldID.Value == user.UserType) {
             *          lblerrormsg.Text = "Cannot Delete UserType! The userType is being applied to existing Users!!";
             *          return;
             *      }
             *  }
             *  catch (Exception ex) {
             *      lblerrormsg.Text = ex.Message;
             *  }
             * }*/

            if (!string.IsNullOrEmpty(hdn_fieldID.Value))
            {
                tblUserType dbUserType = UserTypeManager.getUserTypeById(new Guid(hdn_fieldID.Value));

                if (dbUserType != null)
                {
                    bool statusOfDelete = UserTypeManager.deleteUserType(dbUserType);

                    lblerrormsg.Text  = statusOfDelete ? "UserType Deleted Successfully!!" : "Couldnot Delete UserType";
                    hdn_fieldID.Value = "";
                    bindData();
                }
            }
        }
Exemplo n.º 12
0
        public ActionResult SaveUser(string UserType)
        {
            var data = db.tblUserType.Where(x => x.Name == UserType).Count();

            if (data > 0)
            {
                TempData["Msg"] = "" + UserType + "" + " " + " Is already exists. ";
            }
            else
            {
                tblUserType type = new tblUserType();
                type.Name   = UserType;
                type.Status = false;
                db.tblUserType.Add(type);
                db.SaveChanges();
                ModelState.Clear();
                TempData["Msg"] = "Saved Successfully";
            }
            return(RedirectToAction("RoleSettings"));
        }
Exemplo n.º 13
0
 public void LoadById(Guid id)
 {
     try
     {
         using (PortfolioEntities dc = new PortfolioEntities())
         {
             tblUserType userType = dc.tblUserTypes.Where(ut => ut.Id == id).FirstOrDefault();
             if (userType != null)
             {
                 Id          = userType.Id;
                 Description = userType.Description;
             }
             else
             {
                 throw new Exception("User Type not found");
             }
         }
     }
     catch (Exception ex) { throw ex; }
 }
Exemplo n.º 14
0
            /// <summary>
            /// Update User Type Information
            /// </summary>
            /// <param name="data">UserType Information</param>
            /// <returns>Number Affected Row</returns>
            public static Tuple <ErrorObject, string> UserType(tblUserType data)
            {
                erros = new ErrorObject();
                try
                {
                    using (HSCMEntities db = new HSCMEntities())
                    {
                        db.Entry(data).State = EntityState.Modified;
                        result  = db.SaveChanges();
                        Message = "Affected Row: " + result.ToString();

                        return(new Tuple <ErrorObject, string>(erros.IfError(false), Message));
                    }
                }
                catch (Exception ex)
                {
                    erros.InfoError(ex);
                    return(new Tuple <ErrorObject, string>(erros, String.Empty));
                }
            }
Exemplo n.º 15
0
 public int Update()
 {
     try
     {
         using (PortfolioEntities dc = new PortfolioEntities())
         {
             tblUserType userType = dc.tblUserTypes.Where(ut => ut.Id == Id).FirstOrDefault();
             if (userType != null)
             {
                 userType.Description = Description;
                 return(dc.SaveChanges());
             }
             else
             {
                 throw new Exception("User Type not found");
             }
         }
     }
     catch (Exception ex) { throw ex; }
 }
Exemplo n.º 16
0
        public int Insert()
        {
            try
            {
                using (PortfolioEntities dc = new PortfolioEntities())
                {
                    tblUserType userType = new tblUserType()
                    {
                        Id          = Guid.NewGuid(),
                        Description = Description
                    };
                    //Save the Id
                    this.Id = userType.Id;

                    dc.tblUserTypes.Add(userType);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex) { throw ex; }
        }
Exemplo n.º 17
0
        public void InsertTest()
        {
            using (PortfolioEntities dc = new PortfolioEntities())
            {
                //Create a userType
                tblUserType userType = new tblUserType
                {
                    //UserType a GUID for testing purposes
                    Id          = Guid.Parse("11112222-3333-4444-5555-666677778888"),
                    Description = "Test"
                };

                //Add the userType to the database
                dc.tblUserTypes.Add(userType);

                //Commit changes
                int rowsInserted = dc.SaveChanges();

                Assert.IsTrue(rowsInserted == 1);
            }
        }
Exemplo n.º 18
0
            /// <summary>
            /// Return UserType By Specific ID
            /// </summary>
            /// <param name="id">UserType ID</param>
            /// <returns>UserType By Specific ID Or null If Exist Error</returns>
            public static Tuple <ErrorObject, tblUserType> GetUserType(int id)
            {
                tblUserType UserType = new tblUserType();

                erros = new ErrorObject();

                try
                {
                    using (HSCMEntities db = new HSCMEntities())
                    {
                        UserType = db.tblUserType.Find(id);
                    }
                    erros.Error = false;
                    return(new Tuple <ErrorObject, tblUserType>(erros.IfError(false), UserType));
                }
                catch (Exception ex)
                {
                    erros.InfoError(ex);
                    return(new Tuple <ErrorObject, tblUserType>(erros, UserType));
                }
            }
Exemplo n.º 19
0
            /// <summary>
            /// Update User Type Information
            /// </summary>
            /// <param name="data">UserType Information</param>
            /// <returns>Number Affected Row</returns>
            public static Tuple <ErrorObject, string> UserType(tblUserType data)
            {
                erros = new ErrorObject();
                try
                {
                    using (EileenGaldamezEntities db = new EileenGaldamezEntities())
                    {
                        var row = db.tblUserType.Single(p => p.id == data.id);
                        row.name       = data.name;
                        row.detail     = data.detail;
                        row.upDateDate = data.upDateDate;
                        result         = db.SaveChanges();
                        Message        = "Affected Row: " + result.ToString();

                        return(new Tuple <ErrorObject, string>(erros.IfError(false), Message));
                    }
                }
                catch (Exception ex)
                {
                    erros.InfoError(ex);
                    return(new Tuple <ErrorObject, string>(erros, String.Empty));
                }
            }
Exemplo n.º 20
0
 /// <summary>
 /// There are no comments for tblUserType in the schema.
 /// </summary>
 public void AddTotblUserType(tblUserType tblUserType)
 {
     base.AddObject("tblUserType", tblUserType);
 }
Exemplo n.º 21
0
        protected void btn_save_Click(object sender, EventArgs e)
        {
            //Check if Empty or not
            if (string.IsNullOrEmpty(tb_userType.Text))
            {
                lblerrormsg.Text = "UserType Column Cannot be Empty!!";
                tb_userType.Focus();
                return;
            }

            //Check if already Inserted or not
            foreach (tblUserType UserType in UserTypeManager.getAllUserTypes())
            {
                if (UserType.Name.ToUpper() == tb_userType.Text.ToUpper())
                {
                    lblerrormsg.Text = "UserType Duplicate!! Already Inserted!!";
                    tb_userType.Focus();
                    tb_userType.Text = "";
                    return;
                }
            }

            //To Find if it is a case of Insert or Update
            bool isInsert;

            //Create an Object of Talbe /class tblUserType
            tblUserType userType = new tblUserType();


            if (string.IsNullOrEmpty(hdn_fieldID.Value))
            {
                //Case of Creating a new user Type
                userType.UserTypeID = Guid.NewGuid();
                isInsert            = true;
            }
            else
            {
                //Case of Updating a user type
                userType.UserTypeID = new Guid(hdn_fieldID.Value);
                isInsert            = false;
            }

            userType.Name = tb_userType.Text;

            bool status = UserTypeManager.insertUserType(userType, isInsert);

            //Confirmation of Insert/Edit to the User
            if (status)
            {
                bindData();

                if (isInsert)
                {
                    lblerrormsg.Text = "SuccessFully Inserted New UserType!!";
                }
                else
                {
                    string stat = "updateSuccess";
                    Response.Redirect("~/Web/User/UserTypeList.aspx?stat=" + stat);
                }
            }
            else
            {
                if (isInsert)
                {
                    lblerrormsg.Text = "Cannot Insert New UserType";
                }
                else
                {
                    string stat = "updateFail";
                    Response.Redirect("~/Web/User/UserTypeList.aspx?stat=" + stat);
                }
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Create a new tblUserType object.
 /// </summary>
 /// <param name="userTypeID">Initial value of UserTypeID.</param>
 public static tblUserType CreatetblUserType(string userTypeID)
 {
     tblUserType tblUserType = new tblUserType();
     tblUserType.UserTypeID = userTypeID;
     return tblUserType;
 }