Ejemplo n.º 1
0
        public void CreateResource(Resource resource)
        {
            ResourceRepository resourceRepo = new ResourceRepository();

            try
            {
                var             max = -1;
                List <Resource> rl  = resourceRepo.GetAll().ToList();



                rl.ForEach(r =>
                {
                    var number  = Regex.Replace(r.UserName, "[^0-9]", "");;
                    var usrName = Regex.Replace(r.UserName, "[^a-zA-Z]", "");

                    if (resource.UserName == usrName)
                    {
                        var intUsername = Int32.Parse(number);
                        if (max < intUsername)
                        {
                            max = intUsername;
                        }
                    }
                });


                resource.UserName  += max + 1;
                resource.ResourceID = resourceRepo.GetMaxId() + 1;

                resourceRepo.Add(resource);
                GlobalUnitOfWork.Commit();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }