public Task <int> PostAsync(CreateCommunity item)
        {
            return(Task.Factory.StartNew(() =>
            {
                SqlParameter sponsors;
                SqlParameter tags;
                format_tags_and_sponsors_to_parameter(item.Tags, item.Sponsors, out sponsors, out tags);

                var name = SqlParameterFactory.getVarCharParameter("name", item.Name);
                var local = SqlParameterFactory.getVarCharParameter("local", item.Local);
                var latitude = SqlParameterFactory.getVarCharParameter("latitude", item.Latitude);
                var longitude = SqlParameterFactory.getVarCharParameter("longitude", item.Longitude);
                var description = SqlParameterFactory.getVarCharParameter("description", item.Description);
                var date = SqlParameterFactory.getDateParameter("date", item.FoundationDate);
                var avatar = SqlParameterFactory.getVarCharParameter("avatar", item.AvatarLink);    //para não alterar o procedimento (muito trabalho...)
                var userId = SqlParameterFactory.getVarCharParameter("userId", item.UserId);

                ////Parameter for SP output
                var result = new SqlParameter("result", SqlDbType.Int);
                result.Direction = ParameterDirection.Output;

                try
                {
                    context.Database.ExecuteSqlCommand("EXEC insert_community @name,@local,@description,@date,@avatar,@userId,@latitude,@longitude,@sponsors,@tags,@result OUTPUT", name, local, description, date, avatar, userId, latitude, longitude, sponsors, tags, result);

                    return Convert.ToInt32(result.Value);
                }
                catch (SqlException ex)
                {
                    throw new ArgumentException(ex.Message);
                }
            }));
        }
Ejemplo n.º 2
0
        public Task <int> PostAsync(CreateEvent item)
        {
            return(Task.Factory.StartNew(() =>
            {
                SqlParameter sponsors;
                SqlParameter tags;
                format_tags_and_sponsors_to_parameter(item.Tags, null, out sponsors, out tags);

                var title = SqlParameterFactory.getVarCharParameter("title", item.title);
                var local = SqlParameterFactory.getVarCharParameter("local", item.local);
                var description = SqlParameterFactory.getVarCharParameter("description", item.description);
                var endDate = SqlParameterFactory.getDateParameter("endDate", item.endDate);
                var initDate = SqlParameterFactory.getDateParameter("initDate", item.initDate);
                var nrTickets = SqlParameterFactory.getIntParameter("nrTickets", item.nrOfTickets);
                var communityId = SqlParameterFactory.getIntParameter("communityId", item.communityId);
                var latitude = SqlParameterFactory.getVarCharParameter("latitude", item.latitude);
                var longitude = SqlParameterFactory.getVarCharParameter("longitude", item.longitude);
                var qrcode = SqlParameterFactory.getVarCharParameter("qrcode", item.qrcode);

                ////Parameter for SP output
                var result = new SqlParameter("result", SqlDbType.Int);
                result.Direction = ParameterDirection.Output;

                try
                {
                    context.Database.ExecuteSqlCommand("EXEC insert_event @communityId,@title,@local,@description,@nrTickets,@initDate,@endDate,@tags,@latitude,@longitude,@qrcode,@result OUTPUT", communityId, title, local, description, nrTickets, initDate, endDate, tags, latitude, longitude, qrcode, result);
                    return Convert.ToInt32(result.Value);
                }
                catch (SqlException ex)
                {
                    throw new ArgumentException(ex.Message);
                }
            }));
        }
Ejemplo n.º 3
0
        protected Task <string> N_To_N_operation(int entityId, string userId, string query)
        {
            return(Task.Factory.StartNew(() =>
            {
                try
                {
                    var id = SqlParameterFactory.getIntParameter("id", entityId);
                    var uId = SqlParameterFactory.getVarCharParameter("userId", userId);

                    context.Database.ExecuteSqlCommand(query, id, uId);

                    return userId;
                }
                catch (SqlException ex)
                {
                    throw new ArgumentException(ex.Message);
                }
            }));
        }